Checking for purge prevents caching

Anton Stonor stonorn at giraffen.dk
Mon Mar 19 21:54:43 CET 2007


I don't know if this is a weird bug or my lack of vcl knowledge, so here 
we go:

I want this behavior: When somebody hits <ctrl>-F5 in a browser, varnish 
will purge the current page from the cache.

Firefox puts this in its request header when you do that:

Cache-Control: no-cache

So I inserted this piece of vcl:

--
sub vcl_hit {
   if(req.http.Cache-Control == "no-cache") {
     set obj.ttl = 0s;
     error 200 "Hey, we got a purge";
   }
}
--

At first glance that kind of works. When somebody hits <ctrl>-F5 the 
page gets purged and I get my custom error message.

However suddenly the page is not served from the cache _at all_. That is 
unless I just hit F5, _then_ I get a cached page. Hitting F5 sends this 
request header in Firefox:

Cache-Control: max-age=0

I don't send any caching headers on the backend if that matters, just 
relying on the default Varnish fallback to 120 sec.

Any ideas?


/Anton



More information about the varnish-misc mailing list