-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set cache headers for 404 and 400 to 0 #649
Conversation
Fastly caches 404 headers by default. This could cause issues when rolling out a new registry and a path was requested to early. This sets the cache time to 0. Fastly docs: https://docs.fastly.com/en/guides/http-status-codes-cached-by-default
handler.go
Outdated
@@ -17,10 +17,12 @@ import ( | |||
var errResourceNotFound = errors.New("resource not found") | |||
|
|||
func notFoundError(w http.ResponseWriter, err error) { | |||
cacheHeaders(w, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to change the internal implementation. The recommended for Cache-Control value for not cachable resources is:
Cache-Control: no-cache, no-store, must-revalidate
see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control (Preventing caching)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about using "private"? https://docs.fastly.com/en/guides/configuring-caching#do-not-cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm.. "private" is to inform the intermittent servers not to cache data, because they will be cached by browsers. To prevent caching on the browser level, AFAIK you need to add Max-Age: 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to the Mozilla docs, Cache-Control: no-store
should be sufficient at this point:
no-store
The response may not be stored in any cache. Although other directives may be set, this alone is the only directive you need in preventing cached responses on modern browsers. max-age=0 is already implied. Setting must-revalidate does not make sense because in order to go through revalidation you need the response to be stored in a cache, which no-store prevents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fastly does not respect no-store
:
Fastly does not currently respect no-store or no-cache directives. Including either or both of these in a Cache-Control header has no effect on Fastly's caching decision, unless you alter this behavior using custom VCL.
This now sets
This should work for browser and especially Fastly too. |
Fastly caches 404 headers by default. This could cause issues when rolling out a new registry and a path was requested to early. This sets the cache time to 0.
Fastly docs: https://docs.fastly.com/en/guides/http-status-codes-cached-by-default