Hi All,
I am trying to disable cache for HTML responses. I have these rules already in dispatcher config,
<LocationMatch "^/content/.*\.html$">
Header always unset Cache-Control
Header always unset Expires
Header always set Cache-Control "no-store, no-cache, max-age=0, must-revalidate"
Header always set Pragma "no-cache"
Header always set Surrogate-Control "no-store"
</LocationMatch>
However, when I check response headers I still see this:
cache-control: no-store, no-cache, max-age=0, must-revalidate,max-age=300
It looks like max-age=300 is being appended somewhere. I want to know from where this default Cache-Control: max-age=300 is getting added? What is the recommended way to override / remove this so my own no-cache rules are effective?
Thanks in advance !
Views
Replies
Total Likes
I missed to add this as part of my question. We do not have any other CDN on top of Fastly. And no other rules added on dispatcher for caching.
Views
Replies
Total Likes
Hi @Ganthimathi_R,
I think it's either (a) another vhost/dispatcher rule that sets max-age=300, often in default.vhost or a base file that loads after yours, or (b) publish-side code doing response.setHeader("Cache-Control", "max-age=300…"). Fastly won’t add 300 by itself.
Try this:
<LocationMatch "^/content/.*\.html$">
# wipe both header tables
Header unset Cache-Control
Header always unset Cache-Control
Header unset Expires
Header always unset Expires
# set once, at the very end
Header always set Cache-Control "no-store, no-cache, max-age=0, must-revalidate"
Header always set Pragma "no-cache"
Header always set Surrogate-Control "no-store"
</LocationMatch>
also:
Ensure this block is in the vhost that loads last (or move it to default.vhost), so nothing overwrites it later.
Grep your codebase for setHeader("Cache-Control" and remove any max-age=300 on HTML responses.
and verify:
curl -I https://your.site/.../page.html | tr -d '\r' | egrep -i 'cache-control|surrogate-control'
You should see a single Cache-Control (your value) and Surrogate-Control: no-store.
Views
Replies
Total Likes
The max-age=300 is coming from dispatcher’s default caching (not Apache).
In dispatcher.any, allow dispatcher to forward your custom headers instead of appending its own:
/cache
{
/headers
{
"Cache-Control"
"Pragma"
"Surrogate-Control"
}
}
Then your <LocationMatch> rules will take effect and max-age=300 won’t be added.
Hope this helpful.:)
Regards,
Karishma.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies