Caching WordPress with WP-Cache in a spam filled world

WP-Cache and spam. Who’d have thought they were related? Unfortunately they are because when your blog is spammed WP-Cache doesn’t check if the comment is legitimate or not and deletes cached files related to the spammed post.

I noticed this happened a lot on In after I added thumbnails to the top of the page. The thumbnails change when the page is regenerated but I noticed that they would change much more frequently than expected. After some debugging I realised that comment spam was invalidating the WP-Cache cache.

How do you fix this? Here’s a small patch that can be applied to wp-cache-phase2.php, version 2.0.19 (and probably lower) that checks if the submitted comment was moderated or not. You’ll also find wp-cache-phase2.txt below. Just rename that to .php and copy it into your plugins/wp-cache/ folder for it to work.

Remember to update WP-Cache too. Despite last year’s date on the above post, it was updated as recently as last month!


  1. wp-cache-phase2.diff
  2. wp-cache-phase2.txt

Patch will be on it’s way to gallir in a few moments but if you’re using WP-Cache this could be a big help to your site. (and if you use Ultimate Tag Warrior I hope you’re using my patch?)

11 thoughts on “Caching WordPress with WP-Cache in a spam filled world

  1. Thanks for that, Donncha. I’ve been aware of that problem in the back of my brain for a while, but I never remembered it at a time when I had time to hunt it down and fix it for myself. I bet this will help reduce load on my server a lot when spammers are hitting me with a big run.

  2. Thanks for this, one question though: Did you investigate what happens if Akismet eats the spam? Does that invalidate the cache? (I suppose I could check myself…)

  3. Dougal – I’m glad I’m not the only one to notice this! Hopefully it’ll make a difference next time the spammers come calling.

    James – You mean when Akismet marks a comment as spam? Then the cache isn’t invalidated because it’s status is set to “spam” and not “1”. On the other hand, if you’re talking about times when spam comments disappear after talking to the Akismet server, I don’t know, but I think it will *not* invalidate the cache because of the check on comment_status.
    Disappearing spam comments is a bug or a network problem and it’s probably hard to debug and trace. I’ve never noticed it happening but given the ratio of spam vs legit comments I doubt that any real comments would have been harmed.

  4. Great post, I’m glad there’s people out there who catch this kind of stuff 🙂 Do you know if it also caches comments when they’re awaiting approval (not caught by Akismet)?

  5. Pingback: SigT

Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.