WordPress 2.0 Cache Is Broken!


WordPress takes a bite. As of version 2.0 of WordPress you’ll get a caching feature, which means it’ll ‘remember’ the most frequent accessed static information from your blog. This way it’s supposed to not bother the database but make a ‘fast trip’ to the server to fetch these pieces of info. In the end this should make your weblog go faster, because the information is already there to present.

Unfortunately it’s broken. At least on ThinkLemon.com it is and maybe all websites running PHP Safe Mode (although I haven’t pinpointed it to that ‘feature’). Today, after a lot of ‘hacking’, I found out that although my ‘wp-content/cache’ dir is writable, it won’t create a cache. Each page-request tries to build a cache, but fails miserably along the way. In short, it wastes a lot of time and resources doing nothing in result. Maybe that’s why I found WP 2.0 to be sluggish

I’ve pinpointed my troubles to cache.php in the wp-includes dir, specifically:

if (!file_exists($this->cache_dir."index.php")) {
	@ touch($this->cache_dir."index.php");
}

// Acquire a write lock. 
$mutex = @fopen($this->cache_dir.$this->flock_filename, 'w');
if ( false == $mutex)
	return;
flock($mutex, LOCK_EX);

Problem #1: My webserver happily tries to create $this->cache_dir."index.php". But in the end there’s no such file present. Apparently the @ touch directive does NOT execute, therefore NOT creating the ‘index.php’. But it doesn’t fail at this point.
Problem #2: It tries to acquire a file-lock on the caching dir. Now it really fails, because from this point on it never executes any caching action. Although it finishes all other PHP functions.

Conclusion: If you’ve just upgraded, like me, you may want to check if your cache is working allright. You can find out quickly doing a ‘view source’ and looking at the bottom. WordPress is so kind as to provide some stats. If your number of queries is pretty high (20+) your cache is probably broken. Provided you’re not running dozens of plug-ins… You may want to disable your cache.
If you haven’t upgraded yet, maybe it’s a good idea to wait for version 2.0.1.

Disable the WordPress Cache: Open up wp-config.php. And add the following lines:

// Cache disabled. Comment out to enable.
define('DISABLE_CACHE', true);

Now it won’t try to create a cache.

But wait, there’s more! Even though you’ve disabled your cache, WP 2.0 still makes a lot of calls to caching functions. I’m seeing a lot of ‘wp_cache_get(…)’ after disabling. Which sounds absurd if I disabled the cache… This is something the WordPress team really needs to address.

Update (2006-02-02): I just ran a small test with the new 2.0.1 update, but I still can’t find a cache anywhere. Good thing is, it doesn’t matter if I disable or enable the cache. It still runs the same amount of queries no matter what. Looking into it …

, , , , ,

12 responses to “WordPress 2.0 Cache Is Broken!”

  1. […] PS. Just got to the point where I couldn’t launch emacs on the server without killing Apache first. Action time. I disabled the built-in cache (as described here), then installed WP-Cache 2.0 plugin (I did have an earlier version of this installed prior to upgrading WP, it worked well), seems much improved so far. […]

  2. Great post – Thanks for researching this so thoroughly. I chose WordPress as a CMS for my client’s small web site. I’m at a loss to explain why it’s performing so slowly. Steps I’ve taken so far: 1) Disabling Pings, 2) Updating my Plug-ins without effect.

    Should I disable the cache as you suggest? You mention a ‘wp-content/cache’ directory that I don’t have.. Could that be causing the problem also? I appreciate your feedback, and thanks again!

  3. Tara,

    If you’re able, disable all plugins and revert to the default Kubrick theme. Now test to see if it’s still performing slow. It could be a bug with one of the plugins or an error in your custom theme. If performance is back up, enable plugins/theme one by one and test to see if it makes a difference.
    If it still performs slowly, you may want to add the “define(‘DISABLE_CACHE’, true);” line to your wp-config.php. It doesn’t hurt.
    Now if it still performs slow I’m at a loss. It probably has something to do with your host.

    Another approach would be to mannually add the ‘cache’ dir in the ‘wp-content’ dir. Chmod it to 777 (world writable). Browse the site with your browser and see if there’s any content in ‘wp-content/cache’.

    Cheers,
    Caspar

  4. I created the cache folder and now I’m caching 🙂 Like you, though, I’m not finding that it’s a significant performance improvement.

    Well, I’m glad I found your blog. many thanks!

  5. I think I have problems with the cache too.
    Sometimes my page shows “Your database is already up to date” or something like that.
    Now I have add the define(’DISABLE_CACHE’, true);
    Hope it will solve the problem.
    Thanks for your advice buddy!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.