Purge object on POST or PUT

Hugo Cisneiros (Eitch) hugo.cisneiros at gmail.com
Mon Jun 18 21:57:53 CEST 2012


On Mon, Jun 18, 2012 at 12:18 PM, Martin Hewitt <martin.hewitt at gmail.com> wrote:
> I'm looking at configuring Varnish to run infront of a CouchDB-based
> database cluster. These two, sadly, don't work perfectly together, but
> I'd like to know if it's possible to force a re-fetch of an object at
> a given URL after a POST or PUT has been sent to said URL.
>
> An example flow would be:
>
> 1. GET /database_name/ObjectId
> - Object is fetched from the backend and placed in cache
> 2. GET /database_name/ObjectId
> - Object is served from cache
> 3. POST /database_name/ObjectId
> - I'm currently using pass; to send through all POST and PUT requests,
> so the updated object now exists in the database
> - Here is where I'd like to purge the object in the cache
> 4. GET /database_name/ObjectId
> - Object is fetched from the backend and placed in cache
> 5. GET /database_name/ObjectId
> - Object is served from cache
>
> Currently, after the POST in [3], the subsequent GET passes the
> original, now stale, object from the cache, as the headers don't
> indicate that it should be updated. This header issue is why I'd like
> to force a purge based on my knowledge of what the system will do,
> instead of relying on the headers.

Have you tried using the PURGE/BAN method? For example, on vcl_recv
you can do something like this (very generic and not tested):

if (req.request == "POST" || req.request == "PUT") {
   ban("req.http.host == " + req.http.host + " && req.url == " + req.url);
}

This way, every post or put request will add the requested URL to be
passed on the next request.

See more on this issue in:
https://www.varnish-cache.org/docs/trunk/tutorial/purging.html

If you use the ban list, remember to tune the ban lurker parameter :)

-- 
[]'s
Hugo
www.devin.com.br



More information about the varnish-misc mailing list