varnish cache keys

Poul-Henning Kamp phk at
Mon Nov 17 19:33:00 CET 2008

In message <gfs8bl$d3k$1 at>, Miles writes:
>Can someone confirm the default behaviour of varnish in terms of it's 
>cache keys?
>By default - and without a vary header - is the cache keyed on hostname 
>and url only?  If a vary header is added, then the cache also uses those 
>headers to key the request.

Vary headers are handled correctly, but not as part of the hash since
that is impossible.

When you get a request from a client, you don't know what headers
the backend would want you to vary on, so you cannot add those
headers to the hash string before the lookup.

Therefore you have to, and Varnish does, hash on Host+URL and then
having found an "object head", examine all the objects hung from
that head, as to Vary compatibility.

>Specifically, are cookies are ignored by the cache unless specified in 
>the vary header or special behaviour in VCL?

Cookies by default disables caching and do not get added to hash strings
unless you do so in VCL.

Cookies are not assumed to be in Vary either.

>I'm trying to understand why we get a low level of cache hits, and want 
>to be certain of the facts.

Most likely cookies disabling caching entirely.

Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.

More information about the varnish-misc mailing list