Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set Varnish Cache-Control Headers

I am hoping someone can advise on the proper method for getting Varnish to send cache-control headers. Currently, my configuration is sending "Cache-Control: no-cache" to clients.

Thanks in advance to anyone who might be able to help...

like image 350
Kevin Gleeson Avatar asked Jan 25 '12 20:01

Kevin Gleeson


People also ask

Does Varnish cache headers?

Varnish will, in the default configuration, not cache an object coming from the backend with a 'Set-Cookie' header present. Also, if the client sends a Cookie header, Varnish will bypass the cache and go directly to the backend.

What happens if you don't set Cache-Control header?

Without the cache control header the browser requests the resource every time it loads a new(?) page.


2 Answers

Varnish ignores Cache-Control: nocache as per the documentation. Here is evidence confirming that:

http://drupal.org/node/1418908

To get that result, you should detect the header Cache-Control .nocache. from your backend, and then invalidate the cache, set the backend response to not cacheable, or issue max-age: 0 in the other header (I forget the name right now).

like image 179
Rudd-O Avatar answered Oct 04 '22 14:10

Rudd-O


[ivy] has good advice, and/but it gets a little complicated when you try to obey a servers intent for end user (browser) caching. I found this resource to be helpful in understanding a way to configure Varnish to hold onto a cache longer than a browser is instructed to...

https://www.varnish-cache.org/trac/wiki/VCLExampleLongerCaching

like image 24
Nate- Avatar answered Oct 04 '22 14:10

Nate-