You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a longstanding bug preventing cached controllers that specify an alternate view from being retrieved correctly.
Use case:
Call a controller as either the parent controller or as an include within another controller.
Provide a view directive within said controller that specifies a view other than the default.
Provide a cache directive within said controller to cache it using the provided view.
Result:
The controller is rendered and cached, but the cache item isn't retrieved in subsequent requests.
Workarounds:
Use a separate action different from the default handler() for each view so app.cache.set() creates a unique cache object for each action, and therefore each view
For includes only: specify the view in the calling controller via the include directive so the cache check in server.js includes the view as a parameter
This happens because server.js checks for the existence of the controller cache before firing the controller itself (which is the whole point of caching it), which means if you cache a controller with an alternate view directive, that cache item can never be retrieved because the view is part of the cache key, and the view directive isn't known until after the controller is fired.
Looking at rendering logic in server.js, a second cache.exists() call after the controller is called to get the alternate view directive would avoid rendering time, but the controller itself would still have done its work, negating most of the value of caching it.
The only resolution I can think of is to specify the view in some way prior to the controller call, such as a URL parameter, but my gut tells me that allowing that behavior is a security risk (potential for hacking the URL and calling a view the dev didn't intend for the context).
It's likely this issue will never be resolved, so this ticket serves as a log/reminder of its existence because the question keeps coming up and I need to keep reinvestigating it to remember why it's still there. Maybe someday I'll have an epiphany as to the solution.
Edit: The new controller config is a possible workaround for this, but it feels a bit hacky:
jaysylvester
changed the title
Fix caching of include controllers that specify an alternate view directive
Fix caching of controllers that specify an alternate view directive
May 23, 2021
jaysylvester
changed the title
Fix caching of controllers that specify an alternate view directive
Fix caching of include controllers that specify an alternate view directive
Nov 26, 2021
jaysylvester
changed the title
Fix caching of include controllers that specify an alternate view directive
Fix caching of controllers that specify an alternate view directive
Nov 26, 2021
jaysylvester
changed the title
Fix caching of controllers that specify an alternate view directive
Cached controllers that specify an alternate view directive can't be retrieved
Nov 26, 2021
There is a longstanding bug preventing cached controllers that specify an alternate view from being retrieved correctly.
Use case:
Result:
Workarounds:
handler()
for each view soapp.cache.set()
creates a unique cache object for each action, and therefore each viewserver.js
includes the view as a parameterThis happens because server.js checks for the existence of the controller cache before firing the controller itself (which is the whole point of caching it), which means if you cache a controller with an alternate view directive, that cache item can never be retrieved because the view is part of the cache key, and the view directive isn't known until after the controller is fired.
Looking at rendering logic in server.js, a second cache.exists() call after the controller is called to get the alternate view directive would avoid rendering time, but the controller itself would still have done its work, negating most of the value of caching it.
The only resolution I can think of is to specify the view in some way prior to the controller call, such as a URL parameter, but my gut tells me that allowing that behavior is a security risk (potential for hacking the URL and calling a view the dev didn't intend for the context).
It's likely this issue will never be resolved, so this ticket serves as a log/reminder of its existence because the question keeps coming up and I need to keep reinvestigating it to remember why it's still there. Maybe someday I'll have an epiphany as to the solution.
Edit: The new controller config is a possible workaround for this, but it feels a bit hacky:
The text was updated successfully, but these errors were encountered: