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 thoughts on “WordPress 2.0 Cache Is Broken!

  1. Pingback: Le Blog d’Alex » Blog Archive » Troubles with WP2 caching feature

  2. Pingback: Raw » WordPress - Help Out Development

  3. Pingback: Gecko Bloggle » Cache are TEH DUMBAH

  4. Pingback: alexking.org: Blog > Upgrading WordPress

  5. Tara Long

    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!

  6. Caspar Post author

    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

  7. Tara Long

    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!

  8. Pingback: Listening Post » Blog Archive » links for 2006-06-06

  9. Pingback: Cache defence : Wordpress guy

  10. Pingback: Cache Wordpress 2 Bermasalah - Catatan Hanging

  11. Jack

    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 *


4 − one =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>