Ghost
Ghost copied to clipboard
Cache control directives stale-while-revalidate and stale-if-error for frontend do not get sent even when Ghost config is set
Issue Summary
Cache control directive stale-while-revalidate and stale-if-error for frontend do not get sent as header directives even when passed in configuration values for caching.frontend.staleWhileRevalidate and caching.frontend.staleIfError.
Please note code has not been allowed specifically for staleIfError cache control directive config but should be included due to its usage in conjunction with staleWhileRevalidate. Please see MDN docs here on Cache-Control for further information.
Initial changes have been made here it seems https://github.com/TryGhost/Ghost/pull/15734 and I can submit a fix shortly as a PR.
Also, documentation has also not been updated for caching, whereabouts can changes to documentation be submitted?
Steps to Reproduce
- Initial Setup of the Ghost site locally
yarn setup
- Run the site with a custom
maxAgeto ensure environment variables are being passed through and with a customstaleWhileRevalidatevalue to show that this directive is not being received in theCache-Controlheader
export caching__frontend__maxAge=1800
export caching__frontend__staleWhileRevalidate=604800
yarn dev
- Send off a request to the home page and initial post to show it's not being sent
curl -s -i http://localhost:2368/ | grep -i "Cache-Control"
# Output:
# Cache-Control: public, max-age=1800
- Try another post page as well
curl -s -i http://localhost:2368/coming-soon/ | grep -i "Cache-Control"
# Output:
# Cache-Control: public, max-age=1800
Ghost Version
v5.105.0
Node.js Version
v18.20.4
How did you install Ghost?
Local Development on MacOS 15.1.1
Database type
MySQL 5.7
Browser & OS version
No response
Relevant log / error output
No response
Code of Conduct
- [X] I agree to be friendly and polite to people in this repository
Hello @JamesMarino 👋 At first glance this does appear to be a bug, and the PR looks good - thanks for writing tests 🥰
I need to do a bit of internal fact checking to determine what the reason for adding this was, and be sure there’s no major dependency on this bug somewhere. Not gonna get to that before the holidays now.
I wondered if you could share a bit more about what’s behind these changes and in particular if it’s likely you’ll be brining more cache related changes, as it’ll be easier to handle them in a batch :)
No worries @ErisDS - thanks for the feedback.
I thought it would be a good idea to bring the caching config inline with the Cache-Control HTTP spec which seems to be implemented and respected by various CDN providers.
This was mostly all the caching changes that I was planning to bring in unless configuration keys other than frontend such as contentAPI or publicAssets were to be updated with stale-while-revalidate and stale-if-error cache directives as well. Other cache directives could be introduced as configurable parameters but if there no demand from the community for more cache directives this could be left as is for now.
Our bot has automatically marked this issue as stale because there has not been any activity here in some time.
The issue will be closed soon if there are no further updates, however we ask that you do not post comments to keep the issue open if you are not actively working on a PR.
We keep the issue list minimal so we can keep focus on the most pressing issues. Closed issues can always be reopened if a new contributor is found. Thank you for understanding 🙂
Hi @ErisDS - just wondering if there was any thoughts on getting this PR in and if everything was fine internally for this to be merged? Thanks!
Any updates? It will be very useful if this gets merged and starts working.
Our bot has automatically marked this issue as stale because there has not been any activity here in some time.
The issue will be closed soon if there are no further updates, however we ask that you do not post comments to keep the issue open if you are not actively working on a PR.
We keep the issue list minimal so we can keep focus on the most pressing issues. Closed issues can always be reopened if a new contributor is found. Thank you for understanding 🙂