In my application stack, I'm using CouchDB (in this scenario, to all intents and purposes it's a simple REST server) and I want to put Varnish in front of it to alleviate read load.

I know that whenever my application updates a document through POST or PUT that the old document is invalidated but, due to the headers that CouchDB puts out, Varnish doesn't realise this and so continues to serve the old version for subsequent GET requests.

Basically, I'd like to be able to purge the document at a given REST URL when a POST or PUT method is sent to that same URL.

Can I configure Varnish to achieve this?

I could get my application to send a PURGE request after each POST or PUT but I'd really rather the cache be invisible to the application as, for smaller installations, it might be run without Varnish in place.

Basically, in vcl I'd like to do this:

sub vcl_recv {
    if ( req.request == "POST" || req.request == "PUT" ) {

But the purge; method isn't available in vcl_recv


I seem to have achieved something approximating the above by using ban instead of purge - the immediately subsequent request to the POST triggers a GET and further GET requests are served from the cache, so it seems I misunderstood the semantics.

My subroutine is currently:

sub vcl_recv {
    if ( req.request == "POST" || req.request == "PUT" ) {
        ban("req.url == " + req.url);

see this..


basically you are doing a lookup on what you want to pass.. then to the purge in the hit/miss

  • That doesn't appear to work - Varnish is still not fetching the object freshly after the POST. I'm running a simple GET - change - POST - GET and the object returned isn't the changed object. – Martin Jun 18 '12 at 16:47
  • 1
    Turns out I was mis-understanding the difference between purge and ban. A ban line seemed to have the right effect, although it's anyone's guess what will happen under load! – Martin Jun 18 '12 at 17:41
  • A purge in v2.x is now a ban in v3.x -- the terminology change doesn't help (-: At least you have be mindful of it – KM. Jun 18 '12 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.