WordPress Super Cache

Makes WordPress Faster

Introduction

WP Super Cache is a static caching plugin for WordPress. It generates html files that are served directly by Apache without processing comparatively heavy PHP scripts. By using this plugin you will speed up your WordPress blog significantly.

This plugin is a fork of the excellent WP-Cache 2 by Ricardo Galli Granada. WP-Cache 2 caches the pages of your WordPress blog and delivers them without accessing the database. Unfortunately it still means loading the PHP engine to serve the cached files.

WP Super Cache gets around that. When it is installed, html files are generated and they are served without ever invoking a single line of PHP. How fast can your site serve graphic files? That’s (almost) as fast it will be able to serve these cached files. If your site is struggling to cope with the daily number of visitors, or if your site appears on Digg.com, Slashdot or any other popular site then this plugin is for you.

Download and Install

  • Remove any existing instances of WP Cache, as WP Super Cache is a drop in replacement. Don’t forget to delete the files wp-content/advanced-caching.php and wp-content/wp-cache-config.php. Also comment out the WP_CACHE define in wp-config.php.
  • Download the newest version of the WP Super Cache plugin and follow the instructions contained in the readme.txt file. If you have installed WP-Cache before this shouldn’t be any more difficult.
  • After installation, go to the WP Super Cache options page and set your desired cache time.

How it works

A classic method of preparing an under powered site for a Digg front page appearance or a Slashdotting has been to manually save copies of dynamically generated pages, and place them in directories that match the permalinks structure. This method of performance enhancement does help servers handle a higher load without crashing, but is only effective when an oncoming rush of traffic can be anticipated. WP-Cache alone, while helpful, is not adequate in many cases, so WP Super Cache was created to effectively mimic the manual page caching method, but to handle it in an automated fashion.

When a visitor who is not logged in, or who has not left a comment, visits they will be served a static HTML page out of the supercache subdirectory within the WordPress cache directory. If you navigate to that directory you can view an exact replica of your permalink structure as well as the HTML files within the directories.

To determine if a page has been cached, view the source and the last lines on the page should read something like

<!-- Dynamic Page Served (once) in 0.829 seconds -->
<!-- Cached page generated by WP-Super-Cache on 2009-01-12 16:11:54 -->
<!-- Compression = gzip -->

You’ll only see the last line if compression is enabled.

If you have compression enabled it is no longer possible to determine which cache the page was served from without looking at the page headers. Pages served from the WP-Cache “half on” cache will have an extra header.

WP-Super-Cache: WP-Cache

There are many ways of viewing the headers.
With compression disabled, the text <!-- super cache --> will be displayed at the end of the page if the page is served from the static Supercache.

Use ismyblogworking.com to check if compression is working properly. It will also show just how fast your blog is now.

Features

  • A plugin and hooks system. A common complaint with WP Cache was that hacking was required to make it work nicely with other plugins. Now you can take advantage of the simple plugin system built in to change how or when pages are cached. Use do_cacheaction() and add_cacheaction() like you would with WordPress hooks. Plugins can add their own options to the admin page too.
  • Works well with WordPress MU in VHOST or non-VHOST configuration. Each blog’s cache files are identified to improve performance.
  • Normal WP-Cache files are now split in two. Meta files go in their own directory making it much faster to scan and update the cache.
  • Includes this WP-Cache and protected posts fix.
  • Automatically disable gzip compression in WordPress instead of dying.
  • As Akismet and other spam fighting tools have improved, the cache will only be invalidated if a comment is definitely not spam.
  • A “lock down” button. I like to think of this as my “Digg Proof” button. This basically prepares your site for a heavy digging or slashdotting. It locks down the static cache files and doesn’t delete them when a new comment is made.
  • Supercache static files can be regenerated while serving a slightly out of date file. This will significantly lower the load on a busy server with lots of traffic and comments. Think of it as an automatic “lock down mode” for every page on your site.
  • Automatic updating of your .htaccess file. (Backup your .htaccess before installing the plugin!)
  • Don’t super cache any request with GET parameters.
  • Better version checking of wp-cache-config.php and advanced-cache.php in case you’re using an old one.
  • Better support for Microsoft Windows.
  • Properly serve cached static files on Red Hat/Cent OS systems or others that have an entry for gzip in /etc/mime.types.
  • The Reject URI function now uses regular expressions.
  • Supports the Bad Behaviour plugin if installed (Half on mode only).
  • Supports plugins that show a different theme to mobile devices.

Caveats

  • If you’re logged in or have left a comment you’ll never see a super-cached page. You’ll see plain old regular WP-Cached pages instead. That’s not so bad since a huge majority of your visitors will never leave a comment.
  • Mod Rewrite is used to serve the static HTML pages. As fancy permalinks is also a requirement it should already be installed.
  • Some of the more dynamic aspects of your site’s template won’t refresh quite as quickly. For example, recent comment sidebar plugins. Those plugin should use Javascript to load their content instead.
  • Some sites have problems serving compressed html files and need extra configuration.
  • Don’t expect a cheap hosting plan to survive a major traffic spike, even if it is cached!
  • Remember that dynamic content such as that within the sidebar, will only refresh when the cached pages are refreshed. This timeout value can be modified, but cached files will only be removed if you have a healthy mix of static and dynamic requests.
  • Some plugins like SK2 and others that depend on “fresh” data may not work very well, at least until those plugins support this plugin and clear the cache when required.

Performance Benchmarks

Benchmarks coming soon, but under high load, serving static html files will always trump dynamic PHP requests.

WP Super Cache has also been tested under real world load conditions. The following articles appeared on the Digg front page without issue while running WP Super Cache:

Sites using the Super Cache

Here are a few of the sites that used and helped me build and debug WP Super Cache:

All my sites are hosted on Linode and I can’t complain about them. They’re great.

Support queries and requests should be made through the Super Cache forum.