Improving Wordpress Caching: Batcache and Redirects
There’s a great plugin for Wordpress called Batcache by Andy Skelton, which uses memcached as the cache backend for object cache and full page caches. It’s a great piece of code, and using it is a must if you want a scalable distributed cache for your Wordpress install (avoiding the local file system caching WP-Super-Cache offers).
I’ve been running batcache for a while, and noticed that although I set up a query-heavy homepage to be cached for a long while, the homepage query was still running every couple of minutes. So after some digging and logging I came to realize that batcache was missing an important part — caching redirects.
Why is it important to cache redirects? Here’s an example. If I go to http://example.com/, my homepage will be cached. But when I go to http://www.example.com/, the homepage query still runs. This is because the default www to no-www redirect happens at ‘template-redirect’ action time (with canonical_redirect()), which occurs after the main posts query is run. And, batcache wouldn’t cache the redirect itself nor would it associate the www with the no-www version (it differentiates pages by a couple of parameters, including HTTP_HOST, which is different in this case). So any request to http://www.example.com would actually first run the homepage query, then redirect to http://example.com and serve the cached version only then.
After a short correspondence with Andy, he committed a changeset to advanced-cache.php (and readme.txt ) that now enables to cache redirects (off by default, be sure to turn it on!). Great to see such responsiveness from a plugin author, and I hope it helps others as well.
About this entry
You’re currently reading “Improving Wordpress Caching: Batcache and Redirects,” an entry on Life Scaling
- 9.15.09 / 9am
Follow me on Twitter: @orensol
- No public Twitter messages.