The fastest caching combo for WordPress. Am I in a cached Nirvana?

Diagram of the basic operation of a cache
Image via Wikipedia

I hope you’ve recently noticed a significant improvement in the speed of the Division by Zer0.Ā  I’ve done some further testing and I think I’ve discovered the perfect combination of tools which, at least for me, has made everything much snappier.

Last time I was playing around with Dreamhost’s FastCGI option1 as well as trying out a few newer caching plugins since Super Cache didn’t really play nice. Specifically I was testing Hyper Cache and DB Cache and trying to decide which one is better to keep. Well, in the end I figured out that using both is even better, and now I’m going to tell you why šŸ™‚

Hyper Cache

This one is one serious mutha. It basically does the same thing as Super Cache but without requiring you to edit your .htaccess or other such hassle2. All you have to do is activate and go. And the results are really stunning. With it activated, I routinely get pages loading in sub-second speeds (whereas before the average was 2-6 seconds) on cached pages with very low overhead, which means I can withstand traffic spikes.

I was so impressed I spent an afternoon just reloading pages to admire how fast they loaded šŸ™‚

Of course this plugin will not help with javascripts speed so if you have a lot of ’em, you will still notice your site taking a bit. However you should notice that the loading starts immediately and then waits for each javascript to download and run (so you’ll see the page appear in stages) instead of waiting a bit until it even starts loading (while it’s gathering prerunning the php and quering the DB). As such, if you have most of your javascripts loading at the footer (as you should), your content will appear immediately for your audience to start reading, and by the time they’re one the second sentence, the page will have finished.

My main problem was exactly that incidentally, that the content took up to 5 seconds to even appear. As long as the main text is there, I don’t mind so much how long it takes for the rest of the “bling” to load.

Another good thing about hyper cache is that it will not activate if you’re logged in to your wordpress installation. This means that in order to see the speed of your site as it appears to everyone else, you either need to use another browser (I keep a konqueror lying around just for this) or to clear your cookies. On the upside, it means that you almost always see the current version when you make non-content changes, such as editing your theme (as the cache will be automatically cleared if you make content changes.) This really helps if you like to tweak your site layout a lot.

One last (bad) thing I’ve noticed is that if I go ahead and clear all hyper cache. My site will die with an internal server error. I’ve tried this twice now. I do not know if that is because my site would die if hyper cache was not there or because once the cache is cleared, there some heavy duty function running to repopulate it or whatever. I know it happens though. I don’t have to do this anymore however so it’s not really a problem.

Overall, Hyper Cache is an absolute win for people hosting their own WordPress, especially if you’re on a shared hosting plan and even more especially if you’re using Dreamhost PS, as Super Cache is not an option.

DB Cache

This plugin takes a novel approach to caching. Whereas all the other that exist simply save the html output of your content and then serve it to avoid running PHP code each time a page is requested, DB Cache saves database query output to avoid making SQL calls to it.

This has a few significant benefits. First of all, it helps with Search Engine crawlers such as the google bot. Where a normal caching plugin really shines when a lot of people access one specific page, it actually harms you when one agent accesses a lot of pages, since you add the cache-saving to your load, on top of the normal page loading. DB cache on the other hand, by caching common Database queries, can fill exactly that hole which significantly reduces the juice you need to serve all the bots crawling you.

This is becauseeach page of your site, other than the main content and possible some post-related queries (ie similar posts), has basically the same calls. Your recent posts, your tag clouds and category lists, recent comments etc, depending on what widgets and theme you use. These generally don’t change from page to page but for a normal caching plugin on a new page, they still need to be called so that the full html page can be saved.

So by caching all these common calls, you seriously reduce the time one needs to wait on a blank screen before a page can even start loading the content. You also reduce the load when a crawler does his daily thing and you even increase the speed of the occasional visitor from a mobile. While DB cache will not give you the awesome speed hyper cache will on a single page load, it will certainly reduce your overall server’s CPU & RAM load (much more important than bandwidth and disk space for shared hosting) and make visits to uncommon pages quicker.

Another plus which I’ve discovered is when you are using Gallery2 through the wpg2 plugin. Gallery is imho a database chewer because people don’t simply see one image and then leave, but rather switch quickly among a lot of them. As a result, DB Cache is perfectly prepared to grab those common queries done through wpg2 and save them for later, increasing the overall speed.

The caching combo of ultimate speed

Until now I’ve never mixed caching plugins as they all generally worked in the same or similar way. However the distinct way these two worked gave me the impression that they wouldn’t really conflict and might actually complement each other quite well. One of them is built for serving one page to lost of visitors in a short time period, while the other is perfect for serving many pages to one visitor. So I went ahead and activated both of them at the same time

And whatdayaknow, there was no explosion šŸ™‚

What happens at the moment is that generally, a page always has at least a few queries cached by DB Cache. You can even see the cached queries increasing with each time it’s reloaded (when bypassing hyper cache). This in turn allows a non-hypercached page to load quicker which is then saved into hyper cache for further visitors.

So currently you see the results of this experiment. I’d like to believe that my speed at the moment is quite good and others who have followed my advice have experienced similar improvements. I really hope this is the last time I have to play with caches in the future and that the current speeds are not just an illusion.

Let me know of the results if you try the same combo on your own sites.

Reblog this post [with Zemanta]
  1. Since disabled as it seemed to cause more problems than it solved []
  2. And removing it is simple too, unlike Super Cache []

35 thoughts on “The fastest caching combo for WordPress. Am I in a cached Nirvana?

  1. I am surprised more people havent commented. I will add my experience.

    This cache combo reminded me of when I went from dialup to broadband(ok maybe thats a bit over the top). My site was beginning to slow down as my plugins count was approaching 30. I knew I had to do something, prior to reading this post I thought super cache was the only and best option.

    After messing around with super cache and realizing I dident have the know how to modify apache and .htaccess I began searching. I noticed that DB cache had some good reviews, and then I stumbled on this post. I gave it a shot and now I am part of the group of people who hope we never have to mess with cache again, haha.

    Nice post, I like the fact that these plugins are nice and easy installs, I spent over an hour trying to decipher super cache.

    1. I'm glad this was of use to you Mike. Supercache is not that difficult to setup but it's scary when it fails.

  2. I did notice one glitch with the db cache plugin, when new users register and then try to login they get the "invalid passowrd error". I had to disable the db cache plugin until I can find a solution to this.

    Any ideas?

    Another bug which I think would be present on all cache plugins is that when users login they might not see the tabs that I have located at the top of the page, instead they might still see the login form.

    1. Hi Mike, did you ever find a solution to this:

      "I did notice one glitch with the db cache plugin, when new users register and then try to login they get the "invalid passowrd error". I had to disable the db cache plugin until I can find a solution to this. "

      I have the same problem and don't have a clue how to remedy.

  3. Any ideas?

    I would really suggest you contact the developer of the plugin and let him/her know.

    Another bug which I think would be present on all cache plugins is that when users login they might not see the tabs that I have located at the top of the page, instead they might still see the login form.

    Most caching plugins do not activate when the viewer has a logon cookie

  4. I have been looking for a caching solution forever and I think I've found a good one today thanks to you. Thank you.

  5. What kind of problems led you to disabling one of the cache solutions? Also, which one did you disable?

    1. Erh, I'm a bit lost. In this post I didn't talk about problems leading me to disable caches

  6. Ah, I misread your footnates, you were referring to FastCGI. Sorry!

    Btw, do you still like using both caching solutions together?

    1. Well, I've disabled DB-Cache as I was lately running into RAM errors and I think they may have been caused by bad code or something. HyperCache seems to be able to handle stuff alone however

  7. Ah, I misread your footnates, you were referring to FastCGI. Sorry!

    Btw, do you still like using both caching solutions together?

  8. This works very well. I have uninstalled WP-SuperCache and installed the Hypercache – DBCache combo. After a month running on WP 2.7, I'm very happy. My blog runs on Dreamhost which can be a bit slow (though I luv 'em still). I too spent an afternoon just clicking around and marvelling at the speed.

    I could do more tweeks but my page loading is now consistently 3.5 seconds or so for anonymous viewers. That's about as good as one can expect. YSlow suggested a few more tweeks to my .htaccess that I did which helped trim a few more milliseconds off load time too.

    Thanks šŸ™‚

  9. My site runs with Hyper-Cache and I'm very happy with the results. Cached pages will never expire (only when edited by admin) will the DB-Cache combo do any more positive if I install this?

    And how about cSprites, will this plugin work with the Hype-Cache DB-Cache combo?

  10. Thanks' Michael,

    Tried to understand the 'more in depth' you wrote, sorry for asking again but I'm not sure about this.

    I have installed Hyper-Cache (Cached pages will never expire, only when edited) will it be useful to install DB-Cache also with this configuration or will DB-Cache do nothing extra?

    1. I think if you have Hypercache never expiring then probably DB-Cache won't be of much help

  11. Not sure about if you use never expiring- db0 has a good point. I use both Hyper and DB and seem good, but I can't say for sure if running only 1 is just as fast or faster. CSprites definitely will not work with caching plugins at the moment, however- the author says this himself on his site.

    1. I haven't actually tried it but it does look promising. I'll check it out at some point probably but if you do so before me, let me know of the results

      1. It does work super –except if you have some .js files that can't be cached, like Twitter of Feed2js. For the rest, the plugin is worth to be considered in the combo package;-)

  12. Hi db0,

    A bit of bad news: plenty users are reporting compatibility issues between DB cache and WP 2.8.x –basically, it's not possible to add tags while DB cache is active. The problem has been reported to the plug-in developer (http://wordpress.net.ua/db-cache/comment-page-7#c… but so far no reaction from him. Do you know a workaround for this problem? The plugin is really great.

    1. Not really no. Stick to Hyper cache until then and if you get a lot of problems from Bots, just try to reduce their visiting time from robots.txt šŸ˜‰

  13. I have been trying to increase site speed for a while. A recent traffic spike has resulted in many error establishing database connections, even with Super-Cache. Also a mobile site was just going to be a pain in the ass. Now I am going to try these two methods and improve speed. Half my plugins are dedicated to speeding things up.

  14. I have a WP site which pulls in a lot of RSS feeds (like POPurl), running on Godaddy (which sometimes is like SlowDaddy…
    I run WP 2.8.4 but only have pages, and no posts so don't have the problem with the post tagging…

    I should say that with this combo, the site has dramatically increase speed… Very good find…

    Peter

  15. Nice article ! From personal experience, I have to agree with your findings. I've been using Hypercache for over a year now and I've found it to be hands-down the fastest CACHING solution for shared hosting.

    I gave W3 Total Cache 2 attempts (most recently this week) and I've found that

    a) It isn't as fast at Hypercache when it comes to pure caching (i.e., turn off the other features and compare apples to apples).

    b) W3 Total Cache takes a LOT longer to generate a page the first time when no cache exists. I managed to actually get server time-outs on some occasions when testing page cache creation with W3 Total Cache, something that I've never had happen with Hypercache, or even with all Caching plugins turned off.

    The second issue was a deal breaker for me. I must say that I'm on shared hosting (Hostmonster) which I'm fairly happy with.

    So after lots of experimenting, I've come to my own caching cocktail that I really like and would highly recommend.

    I use W3 Total Cache only to Minify and Combine CSS and JS (although I'm having 404 issues with the JS part). I also use the CDN integration with MaxCDN which is very well done and exceptionally easy to use.

    Combine this with Hypercache for the actual caching and DB Cache Reloaded for Database caching, and I have a really fast site!

    Not to knock W3 Total Cache, which I think is a great "All-in-one" solution, but I don't think it is as good at caching alone. Most tests that have been run proving it to be the best involve using ALL the tweaks, which certainly isn't a fair comparison when it comes to page caching alone.

    Certainly, Page caching is only one component, but this is an important point to make because you can get better performance by combining the benefits of different caching plugins as I have found in my case.

    Cheers,
    Sudeep

  16. Pingback: dogscouts.org

Comments are closed.