caching of request with cookies

Harm Verhagen harm.verhagen at
Thu Sep 23 16:26:48 CEST 2010

On Thu, Sep 23, 2010 at 11:22 AM, Stewart Robinson <stewsnooze at>wrote:

> change this in vcl_recv
>     if (req.http.Authorization || req.http.Cookie) {
>         /* Not cacheable by default */
>         return (pass);
>    }
> to
>     if (req.http.Authorization) {
>         /* Not cacheable by default */
>         return (pass);
>    }
> Perhaps your vcl_hash could have this appended to it
>     if (req.http.Cookie) {
>         set req.hash += req.http.Cookie;
>     }
> I haven't tried this but I don't see why you wouldn't have individual
> cache entries for each cookie combo. I think this would flood your
> cache if you use the cookie for session info, but if you just keep
> simple values in cookies then this should be fine.
I'm actually not seeking for a way to cache individual replies per cookie,
that would indeed flood the cache.
I'm looking for a config that does:
    A)  don't cache responses where the response headers say they may not be
cached (read: have a Vary: Cookie header)
    B)  do cache, even when request contains a cookie, when the response
tells it can be cached because it does not have a Vary: Cookie, and caries
valid caching headers (max_age whatever)  (not cached _per_ cookie, but
cached for all requestors.)

So a default config for a website that uses Vary: Cookie response headers to
inform varnish, whether of not responses actually depend on the cookie or

Isn't that how the http specs say it should be done ?  Only the webserver
_knows_ whether the actual response depended on the cookie or not, right ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-dev mailing list