[wp-trac] [WordPress Trac] #14713: Comment cache is never invalidated when new comments are approved or added
WordPress Trac
wp-trac at lists.automattic.com
Fri Aug 27 08:24:17 UTC 2010
#14713: Comment cache is never invalidated when new comments are approved or added
--------------------------+-------------------------------------------------
Reporter: TomUK | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 3.0.1
Severity: major | Keywords: comments cache memcached
--------------------------+-------------------------------------------------
I've recently started using memcached on my high traffic wordpress site.
On line 214 of wp-includes/comment.php there is this block of code:
{{{
$last_changed = wp_cache_get('last_changed', 'comment');
if ( !$last_changed ) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 'comment');
}
$cache_key = "get_comments:$key:$last_changed";
if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
return $cache;
}
}}}
Which seems to determine the cache key for caching the comments in the
wordpress cache. The value of key last_changed is used as part of the
comment cache key, and is set to be the current time if it is not set.
However, last_changed is never updated - meaning when new comments are
added the cache for the old comments is still used (as there is value in
the key referenced by $cache_key which isn't invalidated).
This wouldn't normally be a problem in the normal object cache, but using
memcached means the cache is more persistent between page loads which
causing the problem of comments not updating.
The cache key "last_changed" needs to be deleted whenever comments are
changed, something like:
{{{
/**
* Fix for comment cache never getting invalidated. We need to remove the
last updated cache
*/
function updateLastCommentUpdated(){
wp_cache_delete('last_changed', 'comment');
}
add_action('wp_set_comment_status', 'updateLastCommentUpdated');
add_action('comment_post', 'updateLastCommentUpdated');
}}}
Which I have added to my functions.php file, but should presumably be in
core code somewhere.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14713>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list