Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Varnish purge all variants of a URL?

Tags:

varnish

Varnish 2.1: I'm trying to use http PURGE to get Varnish to renew one cached URL.

While testing, I would get results that seemed strange until I read this bit in the documentation: "If there are several variants of the same URL in the cache however, only the matching variant will be purged. To purge a gzip variant of the same page the request would have to look like this:"

So now if I do these two commands:

curl -I http://example.com/my-url
curl -X PURGE http://example.com/my-url

I get back a 200 Purged response.

And if I do these two:

curl -I http://example.com/my-url -H "Accept-Encoding: gzip"
curl -X PURGE http://example.com/my-url -H "Accept-Encoding: gzip"

I also get a 200 Purged.

Now if I try:

curl -I http://example.com/my-url -H "Accept-Encoding: deflate"

I get back headers that indicate that the Content-Encoding: is "text/html;charset=utf-8", and it has age in the cache. That seems to indicate that "deflate" isn't being supported by my app, which is probably correct.

The page also has an Age: header indicating that it's being cached.

Now how do I purge that? (Am I asking a moot question?)

All of these attempts return "404 Not in cache":

curl -X PURGE http://example.com/my-url -H "Accept-Encoding: deflate"
curl -X PURGE http://example.com/my-url -H "Accept-Encoding: text/html;charset=utf-8"
curl -X PURGE http://example.com/my-url -H "Accept-Encoding: text/html"

Is there a magic way to purge all of the variants of a URL?

like image 585
Mojo Avatar asked Aug 05 '12 18:08

Mojo


1 Answers

Aha, by applying some google-fu, I stumbled on a forum post, that suggests the following:

purge("req.url ~ ^" req.url "$"); 

i.e. using a regexp behind purge, to handle all Accept-Encoding headers.

More info here: http://www.gossamer-threads.com/lists/varnish/misc/15124

.. which means you need to modify your VCL though.

like image 151
favoretti Avatar answered Jan 03 '23 06:01

favoretti