Invalidate the WP_Comment_Query:query() cache when comments are added. Switch last_changed to a counter incremented via wp_cache_incr().

fixes #22024


git-svn-id: https://develop.svn.wordpress.org/trunk@22080 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2012-09-28 12:47:31 +00:00
parent 1500b5a097
commit 67f3ab27b0
1 changed files with 7 additions and 8 deletions

View File

@ -249,16 +249,13 @@ class WP_Comment_Query {
// $args can be whatever, only use the args defined in defaults to compute the key
$key = md5( serialize( compact(array_keys($defaults)) ) );
$last_changed = wp_cache_get('last_changed', 'comment');
if ( ! $last_changed ) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 'comment');
}
$last_changed = wp_cache_get( 'last_changed', 'comment' );
if ( ! $last_changed )
$last_changed = wp_cache_set( 'last_changed', 1, 'comment' );
$cache_key = "get_comments:$key:$last_changed";
if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
if ( $cache = wp_cache_get( $cache_key, 'comment' ) )
return $cache;
}
$post_id = absint($post_id);
@ -1293,6 +1290,8 @@ function wp_insert_comment($commentdata) {
$comment = get_comment($id);
do_action('wp_insert_comment', $id, $comment);
wp_cache_incr( 'last_changed', 1, 'comment' );
return $id;
}
@ -1964,7 +1963,7 @@ function clean_comment_cache($ids) {
foreach ( (array) $ids as $id )
wp_cache_delete($id, 'comment');
wp_cache_set('last_changed', time(), 'comment');
wp_cache_incr( 'last_changed', 1, 'comment' );
}
/**