Ghost icon indicating copy to clipboard operation
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

Open JamesMarino opened this issue 11 months ago • 5 comments

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

  1. Initial Setup of the Ghost site locally
yarn setup
  1. Run the site with a custom maxAge to ensure environment variables are being passed through and with a custom staleWhileRevalidate value to show that this directive is not being received in the Cache-Control header
export caching__frontend__maxAge=1800
export caching__frontend__staleWhileRevalidate=604800
yarn dev
  1. 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
  1. 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

JamesMarino avatar Dec 15 '24 23:12 JamesMarino

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 :)

ErisDS avatar Dec 19 '24 18:12 ErisDS

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.

JamesMarino avatar Dec 20 '24 13:12 JamesMarino

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 🙂

github-actions[bot] avatar Apr 12 '25 14:04 github-actions[bot]

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!

JamesMarino avatar Apr 15 '25 13:04 JamesMarino

Any updates? It will be very useful if this gets merged and starts working.

RadoslavGatev avatar May 26 '25 09:05 RadoslavGatev

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 🙂

github-actions[bot] avatar Sep 17 '25 06:09 github-actions[bot]