Why should you warm your cache?

It is well known that a lot of the performance of your website comes down to your code, your webserver hardware and external caches like Redis & Varnish. There are a ton of articles and books out there for any language or system that explains one or more facets of performance in great detail. However, whatever caching mechanism you use to, you need to keep it up to date. You want new content to be available as soon as possible and still be delivered as fast as your old cached content. You can make sure that your visitors do not have to wait until the new page is built and cached, by keeping your cache warm at all times.

Keeping it warm

Keeping your cache warm can be done in many ways. You can rebuild your internal database cache on every cache clear, as precise as you want to make it. External caches can be done by fetching the url of the content item, for which you can find numerous scripts as well. You can use e.g. a dead link tracker or a spider like HTTrack, that goes through every link on your site. If you have time based cache invalidation, you can drive your cache warming on the same intervals. For big sites that can take a lot of time and resources to keep the cache up to date at all times. If your cache warming takes a lot of time, this can also mean that there is too much time between fetches of the same item, making the cache warming obsolete.

Precise Varnish cache warning

The real beauty however is in having your cache invalidated and warmed right after each other. Whenever you update some content, you can update the cached version. A nice example is the use of the Varnish module in Drupal, which has precise purging of your cache pages in Varnish. You can hook this up to a smart Varnish refresh script, like this one (for Wordpress but easily turned into something more Drupal-like).

“Cache warming”-As-A-Service

When you don’t feel like writing your own fetching scripts or spiders, you can also use a service that does it for you. We at Codelab42 have built exactly such a service, that you can find here: cache-warmer.com.

You can easily configure your cache warming through:

  • a text file with urls,
  • a sitemap.xml,
  • a spider to crawl all urls on your site.

You can start your cache warming manually, schedule them or start them from your own code via a webhook. We also keep a log of all the pages that have been fetched on each job and tell you if we encountered broken pages.

Precise cache warming, as mentioned before, is currently in the pipeline. Soon that will also be possible via a webhook.