Varnish and max-age=0
Girouard, Yanick
Yanick.Girouard at stm.info
Thu Jul 20 20:55:25 CEST 2017
I found my issue... It had nothing to do with the max-age=0 after all, not with the way I was setting beresp.ttl either. I forgot to strip Set-Cookie from the backend response and that's why it wasn't caching... /facepalm.
Thanks for your help!
De : Bender, Charles [mailto:charles at beachcamera.com]
Envoyé : jeudi 20 juillet 2017 14:25
À : Girouard, Yanick <Yanick.Girouard at stm.info>; varnish-misc at varnish-cache.org
Objet : Re: Varnish and max-age=0
Yanick,
You may just need to set beresp.ttl to a value and Varnish should obey it. And possibly unset cookies. For example-
sub vcl_backend_response {
if (bereq.url ~ "somepage\.php" && beresp.status == 200) {
unset beresp.http.cache-control;
beresp.http.set-cookie;
set beresp.ttl = 3600s;
return(deliver);
}
Above example removes cache-control and set-cookie headers (by default Varnish will not cache responses that set cookies), sets TTL to 3600 seconds, and delivers response.
On 07/20/2017 02:14 PM, Girouard, Yanick wrote:
Hi,
We use Varnish to cache for multiple backends and need Varnish to always control what is cached despite what backends could respond. In other words, even if a backend sets Cache-Control headers to never cache its pages, we still want Varnish to cache them based on defined rules (i.e. certain URL patterns or hosts have different TTLs).
We have recently realized that one of our backend always set the following header: Cache-Control: max-age=0, private, must-revalidate
Our VCL unsets the Cache-Control header in vcl_backend_response and sets its own before delivering. By unsetting the Cache-Control header in vcl_backend_response I would expect Varnish to ignore the max-age=0 value and still cache the page as per our other rules, but it seems that the second it sees max-age=0 in the response header, that it makrs the object as not cacheable.
Other than by changing the backend's response to never set max-age=0, is there a way to force Varnish to cach pages even if it returned max-age=0?
Is this even by design or is it a bug?
Thanks,
Yanick Girouard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170720/a34b7c2d/attachment.html>
More information about the varnish-misc
mailing list