Bans and purges in Varnish 3.0

In Varnish 1.0 there was only one way or ejecting content from Varnish. You had to add VCL code that could find the object and set the TTL to zero. The typical, and squid-compatible way of doing it was by creating a new HTTP method and call it "PURGE". The VCL would typically look like this:

sub vcl_hit {
        if (req.request == "PURGE") {
                set obj.ttl = 0s;
                error 200 "Purged.";
        }
}

You'd also probably ad some ACLs in vcl_recv to protect it. Then, I belive it was in one of the 2.0.x releases PHK added "smart purges". These gave you the abilities to kill content based on any request or response header using powerful regular expressions. So, the fancy way of doing the same thing would be achieved with the following VCL:

  sub vcl_recv {
        if (req.request == "PURGE") {
                purge("req.url == " req.url " && req.http.host == " req.http.host);
                error 200 "Purged.";
        }

Of course, as the overhead of doing these "smart purges" for something that can be achieved with simple purges, makes this somewhat nonsensical. The "smart purges" really shine when we do much more complex operations, like purging the cache of all CSS, or every object with a X-Meta-Keywords matching "varnish".

At the time we thought it would be to much to ask to have two different names for something that more or less does the same thing. Well, that turned out not to be true. So, in order to rectify that mistake we are now renaming what earlier was called "smart purges" to "bans".

So, this:

      purge req.http.host == example.com && req.url ~ ^/somedirectory/.*$

now looks like

      ban req.http.host == example.com && req.url ~ ^/somedirectory/.*$

Easy. :-)

Image copyright 2010 by Aaaarrrrgggghhhh! used under CC licence.

05/05/11 11:19 by Per Buer

All things Varnish related

The Varnish blog is where the our team writes about all things related to Varnish Cache and Varnish Software...or simply vents.

SUBSCRIBE TO OUR BLOG

Recent Posts

Posts by Topic

see all

Varnish Software Blog