Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);
share|improve this question
up vote 1 down vote accepted

see this..

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

share|improve this answer
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
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 posting your answer, you agree to the privacy policy and terms of service.

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