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" ) {
purge;
return(pass);
}
}
But the purge;
method isn't available in vcl_recv
Update
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);
return(pass);
}
}