Score:0

Prevent varnish from caching cookie response

kr flag

When varnish returns a cache, does it also return the cookie generated on the backend or only the css, images and html returned to the frontend? I had users tell me that they kept getting the wrong cookies, so I am thinking because the cookies are based on geolocation data that the reason was the varnish cache. If it is so, is there a way to prevent varnish to return any cached data for cookies?

Score:1
in flag

Varnish's built-in VCL behavior will send Set-Cookie headers that were send by the origin server to the client. This will allow the client to have the appropriate cookie set in the browser.

However, because a Set-Cookie header implies a state change, Varnish will not store these results in cache and will return a so-called Hit-For-Miss object for the next 2 minutes.

This means that the next request for that object will automatically bypass the cache. If any of the subsequent backend responses no longer contain the Set-Cookie header, Varnish will consider the response to be cacheable.

See https://github.com/varnishcache/varnish-cache/blob/6.0/bin/varnishd/builtin.vcl#L157-L165 for the built-in VCL that defines this behavior.

Unless your VCL actively intervenes with logic in the vcl_backend_response subroutine, the default behavior will always be in effect and responses containing Set-Cookie headers will not be cached.

Please share your VCL to see whether or not this is the case.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.