Caching based on response header

Barak Yaish barak.yaish at
Thu Sep 15 15:51:24 CEST 2011

Wow, that was quick! :-)

Ok, may I describe my backend and then can you suggest whether or not
Varnish will suite here?

The server (Tomcat) basically acts as a cache, where the key is page url and
the value is some info on the page. Clients accessing the service pass the
url in the request, and if the data exist in the cache, it will be returned
to client, otherwise a default response will be returned to client, and a
background process will start process the page, in its end the page data
will be placed in the cache. So, since Tomcat (java) do not handle network
very well in high scales, I was thinking I could use Varnish to cache
backend responses in case found in the service cache. Isn't it possible to
configure Varnish to fetch from cache based on some header in the request
(in my case it will be the page url that client is querying)?

Hope I was clear enough,


On Thu, Sep 15, 2011 at 4:25 PM, Per Buer <perbu at>wrote:

> Hi,
> On Thu, Sep 15, 2011 at 3:19 PM, Barak Yaish <barak.yaish at>wrote:
>> I'm new to Varnish, and I didn't find in the docs how to do the following
>> - cache the response based on customized HTTP header (which the backend may
>> or may not set), for example cache the response in case the one of the
>> response headers is "SomeHeader".
> How will Varnish know the value of the response header before it has talked
> to the backend?
> Cache lookups happend after we get the request, and at that time the
> response headers are unknown. You need to figure out what content to deliver
> purely based on the request.
> --
> Per Buer, CEO
> Phone: +47 21 98 92 61 / Mobile: +47 958 39 117 / Skype: per.buer
> *Varnish makes websites fly!*
> Whitepapers <> | Video<> |
> Twitter <>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list