From 77e55361958a56dab1305f93a7cfde4e7adc6705 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 11 Feb 2013 18:08:14 +0000 Subject: [PATCH] Use microtime() instead of incrementors for last_changed to to avoid race conditions with cache evictions. Props westi fixes #23448 git-svn-id: https://develop.svn.wordpress.org/trunk@23401 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment.php | 16 +++------------- wp-includes/general-template.php | 2 +- wp-includes/post.php | 9 ++------- wp-includes/taxonomy.php | 9 ++------- 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index d6ecda976c..65e18a7e4a 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -251,7 +251,7 @@ class WP_Comment_Query { $key = md5( serialize( compact(array_keys($defaults)) ) ); $last_changed = wp_cache_get( 'last_changed', 'comment' ); if ( ! $last_changed ) { - $last_changed = 1; + $last_changed = microtime(); wp_cache_set( 'last_changed', $last_changed, 'comment' ); } $cache_key = "get_comments:$key:$last_changed"; @@ -1292,12 +1292,7 @@ function wp_insert_comment($commentdata) { $comment = get_comment($id); do_action('wp_insert_comment', $id, $comment); - if ( function_exists( 'wp_cache_incr' ) ) { - wp_cache_incr( 'last_changed', 1, 'comment' ); - } else { - $last_changed = wp_cache_get( 'last_changed', 'comment' ); - wp_cache_set( 'last_changed', $last_changed + 1, 'comment' ); - } + wp_cache_set( 'last_changed', microtime(), 'comment' ); return $id; } @@ -2050,12 +2045,7 @@ function clean_comment_cache($ids) { foreach ( (array) $ids as $id ) wp_cache_delete($id, 'comment'); - if ( function_exists( 'wp_cache_incr' ) ) { - wp_cache_incr( 'last_changed', 1, 'comment' ); - } else { - $last_changed = wp_cache_get( 'last_changed', 'comment' ); - wp_cache_set( 'last_changed', $last_changed + 1, 'comment' ); - } + wp_cache_set( 'last_changed', microtime(), 'comment' ); } /** diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 85f3bf71f5..4385e4b2e3 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -919,7 +919,7 @@ function wp_get_archives($args = '') { $last_changed = wp_cache_get( 'last_changed', 'posts' ); if ( ! $last_changed ) { - $last_changed = 1; + $last_changed = microtime(); wp_cache_set( 'last_changed', $last_changed, 'posts' ); } diff --git a/wp-includes/post.php b/wp-includes/post.php index 716447f2ae..bab809896e 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3653,7 +3653,7 @@ function get_pages($args = '') { $key = md5( serialize( compact(array_keys($defaults)) ) ); $last_changed = wp_cache_get( 'last_changed', 'posts' ); if ( ! $last_changed ) { - $last_changed = 1; + $last_changed = microtime(); wp_cache_set( 'last_changed', $last_changed, 'posts' ); } @@ -4672,12 +4672,7 @@ function clean_post_cache( $post ) { do_action( 'clean_page_cache', $post->ID ); } - if ( function_exists( 'wp_cache_incr' ) ) { - wp_cache_incr( 'last_changed', 1, 'posts' ); - } else { - $last_changed = wp_cache_get( 'last_changed', 'posts' ); - wp_cache_set( 'last_changed', $last_changed + 1, 'posts' ); - } + wp_cache_set( 'last_changed', microtime(), 'posts' ); } /** diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index cd579d0f8d..cbaecdfa13 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1242,7 +1242,7 @@ function get_terms($taxonomies, $args = '') { $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key ); $last_changed = wp_cache_get( 'last_changed', 'terms' ); if ( ! $last_changed ) { - $last_changed = 1; + $last_changed = microtime(); wp_cache_set( 'last_changed', $last_changed, 'terms' ); } $cache_key = "get_terms:$key:$last_changed"; @@ -2711,12 +2711,7 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { do_action('clean_term_cache', $ids, $taxonomy); } - if ( function_exists( 'wp_cache_incr' ) ) { - wp_cache_incr( 'last_changed', 1, 'terms' ); - } else { - $last_changed = wp_cache_get( 'last_changed', 'terms' ); - wp_cache_set( 'last_changed', $last_changed + 1, 'terms' ); - } + wp_cache_set( 'last_changed', microtime(), 'terms' ); } /**