Caching RESTful Web Services with Varnish

Imran M Yousuf imyousuf at gmail.com
Sat Mar 24 14:04:35 CET 2012


Hi Jonathan,

Thanks for sharing the thread. Per Buer's comment is actually the path
that needs to be taken to resolve it sensibly and successfully. If I
understand correctly, what needs to be done is the backend will issue
PURGE to velocity servers when an URI is to be invalidated. Further
understandings are inline below.

On Fri, Mar 23, 2012 at 11:34 PM, Jonathan Matthews
<contact at jpluscplusm.com> wrote:
> On 23 March 2012 16:05, Imran M Yousuf <imyousuf at gmail.com> wrote:
>> <snip />
>> 1. I want Varnish to evict from cache if a URI that is cached receives
>> a POST/PUT/DELETE to it
>
> I started a thread back in the 2.x days about your point #1:
> https://www.varnish-cache.org/lists/pipermail/varnish-misc/2011-May/020507.html
>
> 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.
>

I think you are right and as I mentioned above I think issue PURGE to
Velocity is what Per Buer is suggesting. Here it suggests that each
Varnish instance in a cluster has to be requested individually; ain't
there a better way for coordinating this synchronization?

>> 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?
>

I think your question was indicating to point 3; to confirm for point
2 & 3 use cases I am referring to a resource as follows:

> GET /cms/c/com.aponn/TRANSCOM/i/5d88a1a4-0a8e-4dda-ba9f-505bff697d6e HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: localhost:8080
> Accept: application/json
>
< HTTP/1.1 200 OK
< Date: Sat, 24 Mar 2012 12:45:07 GMT
< Server: Jetty(7.3.1.v20110307)
< ETag: "d9e940a99d2baa960ad041999f002960"
< Last-Modified: Sat, 24 Mar 2012 10:58:34 GMT
< Cache-Control: no-transform, max-age=300
< Vary: Accept
< Content-Type: application/json
< Via: 1.1 cms.aponiq.com
< Transfer-Encoding: chunked
<

= For Conditional GET =
As we can notice, Cache-Control specifies max-age to 300 seconds; once
that time elapses and velocity receives a  request to this URI, I want
Velocity to go the backend with 'If-Modified-Since' and/or
'If-None-Match' request headers. Is it possible and if so then how?

= For invalidating sub resources =
I think this needs to be done through PURGE too. The use case is
resource '/cms/c/com.aponn/TRANSCOM/i/5d88a1a4-0a8e-4dda-ba9f-505bff697d6e'
has subresources such as
'/cms/c/com.aponn/TRANSCOM/i/5d88a1a4-0a8e-4dda-ba9f-505bff697d6e/f/fieldA'
and so on per field. I want to PURGE them too on PUT/POST/DELETE to
'/cms/c/com.aponn/TRANSCOM/i/5d88a1a4-0a8e-4dda-ba9f-505bff697d6e';
IOW I want to invalidate all resources with URI pattern
'/cms/c/com.aponn/TRANSCOM/i/5d88a1a4-0a8e-4dda-ba9f-505bff697d6e*'

Though PURGE is a possible solution but if it could be done without
PURGE that would be easier. Any ideas?

Thank you,

-- 
Imran M Yousuf
Twitter: @imyousuf - http://twitter.com/imyousuf
Blog: http://imyousuf-tech.blogs.smartitengineering.com/
Mobile: +880-1711402557



More information about the varnish-misc mailing list