﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
14713	Comment cache is never invalidated when new comments are approved or added	TomUK		"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.


"	defect (bug)	closed	normal	3.1	Comments	3.0.1	major	fixed	comments cache memcached	
