Varnish behavior for no cache-control header

1.2k views Asked by At

I am just setting up varnish for my team. And i want to know: if my application does not currently send any cache-control header then what is the behavior of the varnish cache. Does it cache anyway or we need to explicitly send cache-control header with max-age value so that varnish can cache that. I have set up varnish to cache 200, 404, 400 status code response. Thanks.

1

There are 1 answers

6
Jeff Sisson On

This depends on a number of factors: Varnish will not cache any requests where the client sends a Coookie header, or if the server sends a response with a Set-Cookie header. You also can't cache POST requests as they are not idempotent.

That said, if a request does not have cookies attached, and is a GET request, varnish is set to cache a request for 120s by default. This is determined by the default_ttl setting in varnish, and again would only apply to requests that are cache-able in varnish (even without setting a cache-control header).

From the Varnish documentation:

The Cache-Control header can contain a number of headers. Varnish evaluates it and looks for s-maxage and max-age. It will set the TTL to the value of s-maxage if found. If s-maxage isn’t found, it will use max-age. If neither exist, it will use the Expires header to set the ttl. If none of those headers exist, it will use the default TTL

https://www.varnish-software.com/static/book/VCL_Basics.html