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?)

By Donncha

Donncha Ó Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Twitter.

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

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.

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…)

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.

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)?

El problema de WP-Cache en un mundo lleno de SPAM…

A principios de Diciembre Holy Shmoly (un blog en inglés que hace un par de meses descubrí y que cuando habla de WordPress es sumamente interesante) comentaba un problema interesante de WP-Cache.

WP-Cache tiene entre sus objetivos que cuando se env….

New wp-cache-2 release (2.0.20)…

I just released wp-cache version 2.0.20. This version [hopefully] solved three issues:

Blank pages for first request or missing pages in some installations (ticket and patch 516 by Peter Hosey).
Dropped headers in some installations, specifically Fas…

Leave a Reply