Caching RESTful Web Services with Varnish

Jonathan Matthews contact at
Fri Mar 23 18:34:07 CET 2012

On 23 March 2012 16:05, Imran M Yousuf <imyousuf at> wrote:
> Hi,
> I have used Varnish earlier for caching Web Sites and even used ESI
> with Varnish. Now I want to use Varnish to cache RESTful Web Services
> artifacts. The project I am referring to is as follows:
> Here is what the Web Service does:
> 1. Returns Last-Modified, ETag, Cache-Control with max-age
> 2. Returns 'Vary' as applicable.
> 3. No session has been used
> Here is what I can get to work with out of the box VCL:
> 1. Caches for the time period mentioned in max-age
> 2. Does not respond to PUT/POST on the URI being cached
> Here is what I want to achieve:
> 1. I want Varnish to evict from cache if a URI that is cached receives

I started a thread back in the 2.x days about your point #1:

The naive purge I came up with may not be optimal for 3.x (and may not
have been best for 2.x!)

As you'll see through that thread, the opinion of the list seemed to
be that just writing VCL to do it wasn't the way forward. I'm not
*convinced* this is the case however.

> 2. I want Varnish to do conditional GET after cache expires
> 3. I want to evict all sub-resources of a resource (URI) from cache
> upon receiving POST/PUT/DELETE to it

I'm not sure what you mean by this. Can you give us some examples?

Jonathan Matthews
London, Oxford, UK

More information about the varnish-misc mailing list