ThinkLemon

I think there used to be a tagline about (tag)soup here… anyway…


Also visit:


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 …

Previous article: Next article:


12 Responses to “WordPress 2.0 Cache Is Broken!”

  1. Le Blog d’Alex » Blog Archive » Troubles with WP2 caching feature Says:
    January 15th, 2006 at 9:36 pm

    [...] WordPress 2.0 Cache Is Broken! [...]

  2. Raw » WordPress - Help Out Development Says:
    January 27th, 2006 at 2:57 am

    [...] 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. [...]

  3. Gecko Bloggle » Cache are TEH DUMBAH Says:
    February 2nd, 2006 at 10:29 am

    [...] WordPress 2.0.1 seems to have the same issue mentioned at this place…   [...]

  4. alexking.org: Blog > Upgrading WordPress Says:
    March 11th, 2006 at 8:02 pm

    [...] I ran into some caching issues right away on the test server and had to disable cache. [...]

  5. Tara Long Says:
    March 14th, 2006 at 5:57 am

    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 Says:
    March 14th, 2006 at 12:47 pm

    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 Says:
    March 15th, 2006 at 12:50 am

    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. Listening Post » Blog Archive » links for 2006-06-06 Says:
    June 7th, 2006 at 6:00 am

    [...] WordPress 2.0 Cache Is Broken! | Article | ThinkLemon (tags: wordpress cache) [...]

  9. Cache defence : Wordpress guy Says:
    March 24th, 2007 at 12:14 am

    [...] with inbuilt cache but there is some debate over whether this is quite up to scratch as yet; see http://www.thinklemon.com/weblog/2006/01/15/wordpress-20-cache-is-broken/ and [...]

  10. Nick Stallman Says:
    May 23rd, 2007 at 7:54 am

    Just thought you might like to know that @ causes PHP to ignore any errors.
    It does execute the instruction.

  11. Cache Wordpress 2 Bermasalah - Catatan Hanging Says:
    December 20th, 2007 at 10:06 am

    [...] ada perbaikan dari pengembang WP. Namun beberapa blog memberikan solusi permasalahan tersebut. WordPress 2.0 Cache Is Broken! WordPress – Help Out [...]

  12. Jack Says:
    April 15th, 2009 at 10:22 am

    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!

Reply to the article or a commenter

Comment on this article

Please note that your comment may be withheld from immediate publication. Keep your comment on-topic/on-commenter and your comment will be published ASAP. (Off-topic comments will be deleted at the moderator's discretion. Please us the contact form if you feel your comment has been deleted unduely.)


Search

Are you looking for:

Recent Comments

  • Partnerseiten: I don’t even know how I finished up right here, but I...
  • Jaroslav Klokocnik: Gentlemen: we are very glad that thanks to Dr Rajmon (his...
  • Mike Flaugher: I’d like to find a way to filter by dates. I’m on...
  • made a post: Hello there, I found your site by the use of Google at the same...
  • Jayden Lawson: Also – just restart your browser after setting it to...

Recent Articles

Archives


ThinkLemon is proudly powered by pure will-power, determination and lack of direction in general. Furthermore, it sits on a piece of hardware, I have no clue where, that somehow manages to support a webserver, a scripting language, a database and therefore ... a tool to fill this space.

Entries (RSS) | Comments (RSS).