Configuring Varnish for Caching based on Cookies

Per Buer perbu at varnish-software.com
Tue May 24 11:20:25 CEST 2016


On Tue, May 24, 2016 at 11:13 AM, Pinakee BIswas <pinakee at waltzz.com> wrote:

> Hi Per Buer,
>
> Thanks for the response and suggestion. I agree that caching with Cookies
> is a dangerous thing as cookies are mostly user specific and caching could
> leak them.
>
> But the challenge here is that we have few cookies which would be needed
> by the backend. For example, we use a cookie which specifies the country
> for the client/user. The cookie is used by the backend  to figure out the
> country the user is in. But then I would like to cache the pages for a
> specific country. So, all the pages for users in US should be cached with a
> key using the country cookie - was trying this:
>

The preferred way for dealing with issues like countries is to use Vary.
You can have Varnish synthesize a X-Client-Country header and then have the
backend issue a Vary: X-Client-Country. Then Varnish will keep different
pages for different countries apart. In addition a PURGE on a URL will
clean out _all_ variants of the country.

If you modify the hash this becomes more complicated. As you'll have to
invalidate all variants yourself.

-- 
*Per Buer*
CTO | Varnish Software AS
Cell: +47 95839117
We Make Websites Fly!
www.varnish-software.com
<http://info.varnish-software.com/signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20160524/218883bc/attachment.html>


More information about the varnish-misc mailing list