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 Photos.org 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!
Download
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?)
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.
Donncha, thanks for the answer, I meant the first option. Patch applied!
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)?
Is possible to use wp-cache2 with eAccelerator?
Enrique – it should cache pages with comments waiting for approval, yes.