Any response with a session cookie in the Cookie
header is not stored in the Varnish cache. If any part of the cookie matches the regular expression S?SESS[a-zA-Z0-9]*
, NO_CACHE
, or PERSISTENT_LOGIN_*
, the response bypasses the cache.
In all requests for static assets, all cookie headers, including session cookies, are stripped and most responses are stored in the Varnish cache. For more information on exceptions to cache storage, see Stripping cookies from static files.
The full cookie header is sent to your application unaltered by the Varnish cache.
If your application creates different cacheable content dependent on cookie values, you can instruct the Varnish cache to store and return different objects by utilizing the Vary
response header.
Ensure that you are careful while setting cookies with Vary
. The Cloud Platform Varnish implementation can extract and manipulate such cookies. Cloud Platform Varnish ignores all cookies except those named acquia_a
, acquia_b
, acquia_c
, and the one response cookie prefixed with acquia_extract
.
acquia_extract:
Cookie:acquia_extract:WEBSHOP_CART_ID=1234;
Cookie: WEBSHOP_CART_ID=1234
X-Acquia-Cookie-Key: WEBSHOP_CART_ID
X-Acquia-Cookie-Value: 1234
Cache-Control:no-cache
X-Acquia-Cookie-Key
WEBSHOP_CART_ID
Vary:X-Acquia-Cookie-Key,X-Acquia-Cookie-Value
Cookie:acquia_a=blue; | X-Acquia-Cookie-A:blue |
Cookie:acquia_b=green; | X-Acquia-Cookie-B:green |
Cookie:acquia_c=red; | X-Acquia-Cookie-C:red |
Cookie: specific_thing=anything;clicked_banner=0;acquia_a=blue;acquia_b=green;acquia_extract:WEBSHOP_CART_ID=1234;category=shirts;
X-Acquia-Cookie-Key: WEBSHOP_CART_ID
X-Acquia-Cookie-Value: 1234
X-Acquia-Cookie-A: blue
X-Acquia-Cookie-B: green
Cookie: specific_thing=anything;clicked_banner=0;acquia_a=blue;acquia_b=green;WEBSHOP_CART_ID=1234;category=shirts;
acquia_extract:
X-Acquia-Cookie-*
Vary:X-Acquia-Cookie-A
Stripping cookie headers from static assets
Certain file types managed by Drupal in the modules
, themes
, files
, or libraries
directories have incoming cookie headers removed. For more information, see Stripping cookies from static files.
$_COOKIE
Cookie
hook_init
var_dump($_COOKIE);
print_r($_COOKIE);
Reference material
The length of time that a cacheable object is stored in the Varnish cache is determined by the cache control headers, such as Cache-Control
and Cache-Control: s-maxage
. For more information on controlling cache lifetime, read the following articles: