Varnish Headers

Events happening in the community are now at Drupal community events on www.drupal.org.
mpaler's picture

I'm seeing a behavior where varnished pages stay cached for only 10 minutes. Examining my headers, I guess I'm confused about what I should be seeing. Below is an example of the response & request headers for a Pantheon page served up to an anonymous user.

Cache-Control:public, max-age=600
Is this the culprit? Does this seem too short? The varnished page "Age" will go up to 600 and then reset to 0. Before reset the page loads quickly on different browsers, but when it resets, it needs to load the whole page again. Something doesn't seem right there.

Expires:Sun, 11 Mar 1984 12:00:00 GMT
Does this seem correct? Or is this another way of saying never expire?

Cache-Control:max-age=0 (request header)
Is this proper?

Request Headers

Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5
Cache-Control:max-age=0
Referer:http://www.varnishedsite.com/product/-pvi-5300
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4

Response Headers

Age:48
Cache-Control:public, max-age=600
Connection:keep-alive
Content-Encoding:gzip
Content-Length:17539
Content-Type:text/html; charset=utf-8
Date:Thu, 09 Sep 2010 15:52:25 GMT
ETag:"1284047492"-gzip
Expires:Sun, 11 Mar 1984 12:00:00 GMT
Last-Modified:Thu, 09 Sep 2010 15:51:32 +0000
Server:Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.5 with Suhosin-Patch mod_ssl/2.2.11 OpenSSL/0.9.8g
Vary:Cookie,Accept-Encoding
Via:1.1 varnish
X-Powered-By:PHP/5.2.6-3ubuntu4.5
X-Varnish:365987931 365987862

Thanks,
Mike

Comments

Max-age is a common browser

Jonah Ellison's picture

Max-age is a common browser caching mechanism. When a server sends it, the browser will not request the URL again for 600 seconds. When a browser sends max-age=0, it wants to revalidate its cache entry (usually because the 600 seconds are over, or the refresh button is clicked). This is useful for static content that isn't updated such as images.

An expire in the past is a useful way of not allowing the browser to cache the request. Note that just because the browser is not caching request, doesn't mean the page is cached on the server. In fact, this header is required for dynamic content to detect if the page has been updated.

How often is Drupal cron running? This clears the page cache.

Varnish cache & DB cache are different

mikeytown2's picture

unless your running with the varnish module and have "varnish_flush_cron" enabled (not the default) then varnish will not be flushed on cron.

Looking at headers

mikeytown2's picture

Your headers all seem correct; just you have a short ttl (10 minutes). This short time frame is needed because your site might change and it needs to be updated then. Using the varnish module allows you to have a longer ttl. I do have the Cache Expiration module that will allow you to try and have even longer page lifetimes although its not ideal ATM. If your using boost I keep everything in the database and that allow me to keep an accurate record of what content shows up where (if your using the latest dev). Eventually I will port over all the changes from boost into the expires module; only issue with expires is it will then require 2 database tables to keep track of everything (just like I do for boost). I've been trying to avoid database tables but it appears that I need them if I want to do advanced cache expiration; like I do in boost right now.

Examples of advanced cache expiration include (things that require a database):
flushing the view on node edit/create
flushing the panel on node edit (nodes loaded up in via context)

Max Age

joshk's picture

Since you're using pressflow, the Max Age is configurable in your admin/settings/performance page. You can set that to be longer if you like.

The ideal is to set that to be big, and then use a Cache Expiration code-set to expire things as needed. However, you should take the time to think this through and map out a caching strategy for your site.

You can also use Edge Side Includes

alexander allen's picture

You can also try setting the cache for the page to a longer ttl (1 day), then use Edge Side Includes (ESI) to insert into the page elements that refresh more often (such as blocks or the main content area in the home page).

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: