Wednesday, November 02, 2011

Varnish simple purge

So whats a Drupal 7 developer to do if he needs to launch a highly dynamic anonymous site and needs to plan caching strategies? Use Varnish cache of course.

But if your site is as dynamic as mine, Varnish will display stale entries unless its TTL is set to something like 1 hour. For a dynamic news site then, surely you need automatic rules to purge pages from Varnish on new or updated content? For e.g. the homepage is changing constantly! The index pages will also change often.

There are currently two modules in the pipeline that should offer the ability to purge pages (cache ids) from Varnish, instead of the whole Varnish cache (oh God, no!):

  1. Cache Expiration, and
  2. Cache actions

While waiting for these more suited modules to have a stable, usable release on Drupal 7 production sites, I had to create a very simple module -Varnish Simple Purge - that allows site admins/editors to purge individual urls from Varnish.

We don't want to give them too many options, cos by experience we know they will use all :) Finally Varnish will more often be empty - not a good state to be in.

Hence with a Varnish TTL of 1hour and a simple purge mechanism to purge pages immediately if needed, my news site is working way faster than its non Drupal predecessor. Oh did I forget to mention that this site is a port from a bespoke CMS to Drupal?

Other cache clearing mechanisms we use are time based views cache (in-built in views). What we would really love is this port of Views Content cache.

No comments: