1

We have a D7 site I'm trying to cache with Varnish. The assets are caching fine but for some reason every page is served with this header:

Cache-Control:  no-cache, must-revalidate, post-check=0, pre-check=0

The pages are quite heavy to render and end users aren't authenticated, so I'd really like to find a solution. How can I find out if a module is preventing caching? What else could cause this? We have a similar site that plays completely nice with Varnish but I haven't been able to spot the difference yet.

Edit: I checked the site with http://www.isvarnishworking.com/ and it says Varnish is working - "sort of". That is, the age is smaller than one, meaning something is preventing the page from being cached. Below are the full response headers as reported by the service.

Server: Apache
X-Drupal-Cache: MISS
Expires:    Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified:  Mon, 27 Apr 2015 17:11:55 GMT
Cache-Control:  no-cache, must-revalidate, post-check=0, pre-check=0
ETag:   "1430154715"
Content-Language:   en
X-Generator:    Drupal 7 (http://drupal.org)
Content-Type:   text/html; charset=utf-8
Content-Length: 45567
Accept-Ranges:  bytes
Date:   Mon, 27 Apr 2015 17:11:56 GMT
X-Varnish:  1868715414
Age:    0
Via:    1.1 varnish
Connection: keep-alive
X-Varnish-Cache:    MISS
1

Inspect your HTTP headers and see if session or other cookies are being set. This is the most common cause of Varnish "not working." Also make sure you are not logged in, and you can test using http://www.isvarnishworking.com/ to see what headers are outputted. If you could paste the headers would be helpful.

  • Thanks, that seems like a pretty useful link! I added the headers to my question. – Kaivosukeltaja Apr 27 '15 at 17:15
  • What about sessions? Its easy in Firefox, go to page, then right click "View Page Info" then click on Security tab and click View Cookies. From there click Remove All and then reload your home page. There should not be any SESSxxxxx cookies, if you could screen shot or list all cookies. – pgrujic Apr 27 '15 at 18:22
  • It sends cookies has_js, _ga, _gat, __atuvc and __atuvs. Our other site also sends the same cookies and it works fine. All the cookies are JavaScript originated, so they shouldn't affect caching or headers. – Kaivosukeltaja Apr 27 '15 at 18:52
  • Yeah I just wanted to see if there was a session cookie set as that would break cache. You can force varnish to cache by adding something like: sub vcl_fetch { remove beresp.http.Cache-Control; set beresp.http.Cache-Control = "public"; } – pgrujic Apr 28 '15 at 14:43
  • Also another thing that helps is disabling Varnish and seeing if Drupal will cache the page. If no then you should focus on reviewing the modules and if any of them set FALSE for cache. I am assuming you have cache configured with varnish in settings.php – pgrujic Apr 28 '15 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.