Prevent varnish from caching cookie response
Solution 1:
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 containingSet-Cookie
headers will not be cached.
Please share your VCL to see whether or not this is the case.