Craft Cloud should not statically cache some actions/controllers e.g. actions/app/health-check #54
Replies: 4 comments 3 replies
-
The health check has been set to have no cache headers in an upcoming release: craftcms/cms#16364 A wider question is the caching of certain action paths generally. I feel there is both good and bad points for doing it. |
Beta Was this translation helpful? Give feedback.
-
It looks like in the next major Craft CMS release, all action controller requests are going to get the no-cache headers by default. You will be able to override this in controllers if required. This does have an impact on Craft Cloud, where (if released) Craft CMS 4.14 and Craft CMS 5.6 will now be opt-in for action controller caching rather than it being cached by default. This will have some changes needed for: https://craftcms.com/knowledge-base/cloud-static-caching as since general release, that isn't the default behaviour. I am inclined to agree that the amount of controllers from plugins and modules, static caching is probably not something considered and may do more harm than good. Being able to opt-in however, is consistent and allows you to still take advantage of it. This is specifically in actions/controllers, front end web requests remained unaffected. |
Beta Was this translation helpful? Give feedback.
-
I feel somewhat responsible for opening up pandora's box on this, so I want to make sure that Craft Cloud customers (that includes our organisation) aren't caught out on the next release if it goes ahead with the commit. I think ultimately, not caching action requests by default is the best move, because I think with the amount of plugins and modules out there, static caching isn't default in Craft CMS itself and not something plugin developers may have considered. Craft Cloud excluding certain action paths from static caching could be an option, but that's committing to maintaining a bypass list, which would have to keep in sync with Craft CMS and possibly would end up having to bypass well used plugins too most likely. The fact that the health-check endpoint was missed (it happens, not major) shows that perhaps that's not really a maintainable option either long term. The concern I guess is those that are benefiting from the existing default cache behaviour and then if 4.14 and 5.6 releases with that change, completely changes the behaviour the other way around, meaning, adding I did find myself wanting to disable static caching on one of our Craft Cloud environments to make testing easier, while allowing it on others. Ultimately, I settled with using devMode as the main control flag to then send The main focus is action requests really, as any site/front-end request is unchanged, POST requests weren't cached, so the documentation probably needs to be updated to mention that Craft Cloud's static cache was originally not selective on any GET request, now it will mostly be for site requests only, unless you opt-in with setting cache headers, either through Twig or a PHP controller. |
Beta Was this translation helpful? Give feedback.
-
Worth mentioning that since Craft CMS 5.6, caching on 200 GET action requests are now default opt-out and you need to set cache headers explicitly now. Front end/site requests remain unchanged. |
Beta Was this translation helpful? Give feedback.
-
It looks like static caching gets triggered on the Craft CMS health check endpoint.
https://craftcms.com/knowledge-base/configuring-load-balanced-environments#health-check-endpoint
Because a GET request is used, this gets cached after the first request. Due to the nature and purpose of this action endpoint, I don't think it should be cached at all. It would potentially be something that could be applied within Craft Cloud to basically bypass the
actions/app/health-check
path from ever being cached,This endpoint is designed to always return a 200 when OK and an error response, a 304 is not the intended response for it.
Beta Was this translation helpful? Give feedback.
All reactions