Make WordPress Core

Changeset 60697

Timestamp:
08/31/2025 09:41:54 PM (6 weeks ago)
Author:
spacedmonkey
Message:

Caching API: Use consistent cache keys for query groups.

Query-based caches are now improved by reusing cache keys. Previously, cache keys for query caches were generated using the last_changed value as part of the key. This meant that whenever last_changed was updated, all the previously cached values for the group became unreachable.

The new approach allows WordPress to replace previously cached results that are known to be stale. The previous approach relied on the object cache backend evicting stale keys which is done at various levels of efficiency.

To address this, the following new helper functions have been introduced:

  • wp_cache_get_salted
  • wp_cache_set_salted
  • wp_cache_get_multiple_salted
  • wp_cache_set_multiple_salted

These functions provide a consistent way to get/set query caches. Instead of using the last_changed value as part of the cache key, it is now stored inside the cache value as a "salt". This allows cache keys to be reused, with values updated in place rather than relying on eviction of outdated entries.

Props spacedmonkey, peterwilsoncc, flixos90, sanchothefat, tillkruess, rmccue, mukesh27, adamsilverstein, owi, nickchomey.

Location:
trunk
Files:
4 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/cache-compat.php

    r54448 r60697  
    200200    }
    201201endif;
     202
     203if ( ! function_exists( 'wp_cache_get_salted' ) ) :
     204    /**
     205     * Retrieves cached data if valid and unchanged.
     206     *
     207     * @since 6.9.0
     208     *
     209     * @param string          $cache_key The cache key used for storage and retrieval.
     210     * @param string          $group     The cache group used for organizing data.
     211     * @param string|string[] $salt      The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.
     212     * @return mixed|false The cached data if valid, or false if the cache does not exist or is outdated.
     213     */
     214    function wp_cache_get_salted( $cache_key, $group, $salt ) {
     215        $salt  = is_array( $salt ) ? implode( ':', $salt ) : $salt;
     216        $cache = wp_cache_get( $cache_key, $group );
     217
     218        if ( ! is_array( $cache ) ) {
     219            return false;
     220        }
     221
     222        if ( ! isset( $cache['salt'] ) || ! isset( $cache['data'] ) || $salt !== $cache['salt'] ) {
     223            return false;
     224        }
     225
     226        return $cache['data'];
     227    }
     228endif;
     229
     230if ( ! function_exists( 'wp_cache_set_salted' ) ) :
     231    /**
     232     * Stores salted data in the cache.
     233     *
     234     * @since 6.9.0
     235     *
     236     * @param string          $cache_key The cache key under which to store the data.
     237     * @param mixed           $data      The data to be cached.
     238     * @param string          $group     The cache group to which the data belongs.
     239     * @param string|string[] $salt      The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.
     240     * @param int             $expire    Optional. When to expire the cache contents, in seconds.
     241     *                                   Default 0 (no expiration).
     242     * @return bool True on success, false on failure.
     243     */
     244    function wp_cache_set_salted( $cache_key, $data, $group, $salt, $expire = 0 ) {
     245        $salt = is_array( $salt ) ? implode( ':', $salt ) : $salt;
     246        return wp_cache_set(
     247            $cache_key,
     248            array(
     249                'data' => $data,
     250                'salt' => $salt,
     251            ),
     252            $group,
     253            $expire
     254        );
     255    }
     256endif;
     257
     258if ( ! function_exists( 'wp_cache_get_multiple_salted' ) ) :
     259    /**
     260     * Retrieves multiple items from the cache, only considering valid and unchanged items.
     261     *
     262     * @since 6.9.0
     263     *
     264     * @param array           $cache_keys Array of cache keys to retrieve.
     265     * @param string          $group      The group of the cache to check.
     266     * @param string|string[] $salt       The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.
     267     * @return array An associative array containing cache values. Values are `false` if they are not found or outdated.
     268     */
     269    function wp_cache_get_multiple_salted( $cache_keys, $group, $salt ) {
     270        $salt  = is_array( $salt ) ? implode( ':', $salt ) : $salt;
     271        $cache = wp_cache_get_multiple( $cache_keys, $group );
     272
     273        foreach ( $cache as $key => $value ) {
     274            if ( ! is_array( $value ) ) {
     275                $cache[ $key ] = false;
     276                continue;
     277            }
     278            if ( ! isset( $value['salt'], $value['data'] ) || $salt !== $value['salt'] ) {
     279                $cache[ $key ] = false;
     280                continue;
     281            }
     282            $cache[ $key ] = $value['data'];
     283        }
     284
     285        return $cache;
     286    }
     287endif;
     288
     289if ( ! function_exists( 'wp_cache_set_multiple_salted' ) ) :
     290    /**
     291     * Stores multiple pieces of salted data in the cache.
     292     *
     293     * @since 6.9.0
     294     *
     295     * @param mixed           $data   Data to be stored in the cache for all keys.
     296     * @param string          $group  Group to which the cached data belongs.
     297     * @param string|string[] $salt   The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.
     298     * @param int             $expire Optional. When to expire the cache contents, in seconds.
     299     *                                Default 0 (no expiration).
     300     * @return bool[] Array of return values, grouped by key. Each value is either
     301     *                true on success, or false on failure.
     302     */
     303    function wp_cache_set_multiple_salted( $data, $group, $salt, $expire = 0 ) {
     304        $salt      = is_array( $salt ) ? implode( ':', $salt ) : $salt;
     305        $new_cache = array();
     306        foreach ( $data as $key => $value ) {
     307            $new_cache[ $key ] = array(
     308                'data' => $value,
     309                'salt' => $salt,
     310            );
     311        }
     312        return wp_cache_set_multiple( $new_cache, $group, $expire );
     313    }
     314endif;
  • trunk/src/wp-includes/class-wp-comment-query.php

    r60291 r60697  
    452452        $last_changed = wp_cache_get_last_changed( 'comment' );
    453453
    454         $cache_key   = "get_comments:$key:$last_changed";
    455         $cache_value = wp_cache_get( $cache_key, 'comment-queries' );
     454        $cache_key   = "get_comments:$key";
     455        $cache_value = wp_cache_get_salted( $cache_key, 'comment-queries', $last_changed );
    456456        if ( false === $cache_value ) {
    457457            $comment_ids = $this->get_comment_ids();
     
    464464                'found_comments' => $this->found_comments,
    465465            );
    466             wp_cache_add( $cache_key, $cache_value, 'comment-queries' );
     466            wp_cache_set_salted( $cache_key, $cache_value, 'comment-queries', $last_changed );
    467467        } else {
    468468            $comment_ids          = $cache_value['comment_ids'];
     
    10451045                $cache_keys = array();
    10461046                foreach ( $_parent_ids as $parent_id ) {
    1047                     $cache_keys[ $parent_id ] = "get_comment_child_ids:$parent_id:$key:$last_changed";
    1048                 }
    1049                 $cache_data = wp_cache_get_multiple( array_values( $cache_keys ), 'comment-queries' );
     1047                    $cache_keys[ $parent_id ] = "get_comment_child_ids:$parent_id:$key";
     1048                }
     1049                $cache_data = wp_cache_get_multiple_salted( array_values( $cache_keys ), 'comment-queries', $last_changed );
    10501050                foreach ( $_parent_ids as $parent_id ) {
    10511051                    $parent_child_ids = $cache_data[ $cache_keys[ $parent_id ] ];
     
    10811081                $data = array();
    10821082                foreach ( $parent_map as $parent_id => $children ) {
    1083                     $cache_key          = "get_comment_child_ids:$parent_id:$key:$last_changed";
     1083                    $cache_key          = "get_comment_child_ids:$parent_id:$key";
    10841084                    $data[ $cache_key ] = $children;
    10851085                }
    1086                 wp_cache_set_multiple( $data, 'comment-queries' );
     1086                wp_cache_set_multiple_salted( $data, 'comment-queries', $last_changed );
    10871087            }
    10881088
  • trunk/src/wp-includes/class-wp-network-query.php

    r58454 r60697  
    250250        $last_changed = wp_cache_get_last_changed( 'networks' );
    251251
    252         $cache_key   = "get_network_ids:$key:$last_changed";
    253         $cache_value = wp_cache_get( $cache_key, 'network-queries' );
     252        $cache_key   = "get_network_ids:$key";
     253        $cache_value = wp_cache_get_salted( $cache_key, 'network-queries', $last_changed );
    254254
    255255        if ( false === $cache_value ) {
     
    263263                'found_networks' => $this->found_networks,
    264264            );
    265             wp_cache_add( $cache_key, $cache_value, 'network-queries' );
     265            wp_cache_set_salted( $cache_key, $cache_value, 'network-queries', $last_changed );
    266266        } else {
    267267            $network_ids          = $cache_value['network_ids'];
  • trunk/src/wp-includes/class-wp-query.php

    r60444 r60697  
    28832883
    28842884            $key          = md5( $comments_request );
    2885             $last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );
    2886 
    2887             $cache_key   = "comment_feed:$key:$last_changed";
    2888             $comment_ids = wp_cache_get( $cache_key, 'comment-queries' );
     2885            $last_changed = array(
     2886                wp_cache_get_last_changed( 'comment' ),
     2887                wp_cache_get_last_changed( 'posts' ),
     2888            );
     2889
     2890            $cache_key   = "comment_feed:$key";
     2891            $comment_ids = wp_cache_get_salted( $cache_key, 'comment-queries', $last_changed );
    28892892            if ( false === $comment_ids ) {
    28902893                $comment_ids = $wpdb->get_col( $comments_request );
    2891                 wp_cache_add( $cache_key, $comment_ids, 'comment-queries' );
     2894                wp_cache_set_salted( $cache_key, $comment_ids, 'comment-queries', $last_changed );
    28922895            }
    28932896            _prime_comment_caches( $comment_ids );
     
    32473250        }
    32483251
     3252        $last_changed = (array) wp_cache_get_last_changed( 'posts' );
     3253        if ( ! empty( $this->tax_query->queries ) ) {
     3254            $last_changed[] = wp_cache_get_last_changed( 'terms' );
     3255        }
     3256
    32493257        if ( $q['cache_results'] && $id_query_is_cacheable ) {
    32503258            $new_request = str_replace( $fields, "{$wpdb->posts}.*", $this->request );
     
    32533261            $cache_found = false;
    32543262            if ( null === $this->posts ) {
    3255                 $cached_results = wp_cache_get( $cache_key, 'post-queries', false, $cache_found );
     3263                $cached_results = wp_cache_get_salted( $cache_key, 'post-queries', $last_changed );
    32563264
    32573265                if ( $cached_results ) {
     3266                    $cache_found = true;
    32583267                    /** @var int[] */
    32593268                    $post_ids = array_map( 'intval', $cached_results['posts'] );
     
    33133322                );
    33143323
    3315                 wp_cache_set( $cache_key, $cache_value, 'post-queries' );
     3324                wp_cache_set_salted( $cache_key, $cache_value, 'post-queries', $last_changed );
    33163325            }
    33173326
     
    33513360                );
    33523361
    3353                 wp_cache_set( $cache_key, $cache_value, 'post-queries' );
     3362                wp_cache_set_salted( $cache_key, $cache_value, 'post-queries', $last_changed );
    33543363            }
    33553364
     
    34493458            );
    34503459
    3451             wp_cache_set( $cache_key, $cache_value, 'post-queries' );
     3460            wp_cache_set_salted( $cache_key, $cache_value, 'post-queries', $last_changed );
    34523461        }
    34533462
     
    34873496            $comment_last_changed = wp_cache_get_last_changed( 'comment' );
    34883497
    3489             $comment_cache_key = "comment_feed:$comment_key:$comment_last_changed";
    3490             $comment_ids       = wp_cache_get( $comment_cache_key, 'comment-queries' );
     3498            $comment_cache_key = "comment_feed:$comment_key";
     3499            $comment_ids       = wp_cache_get_salted( $comment_cache_key, 'comment-queries', $comment_last_changed );
    34913500            if ( false === $comment_ids ) {
    34923501                $comment_ids = $wpdb->get_col( $comments_request );
    3493                 wp_cache_add( $comment_cache_key, $comment_ids, 'comment-queries' );
     3502                wp_cache_set_salted( $comment_cache_key, $comment_ids, 'comment-queries', $comment_last_changed );
    34943503            }
    34953504            _prime_comment_caches( $comment_ids );
     
    50635072        $key = md5( serialize( $args ) . $sql );
    50645073
    5065         $last_changed = wp_cache_get_last_changed( 'posts' );
    5066         if ( ! empty( $this->tax_query->queries ) ) {
    5067             $last_changed .= wp_cache_get_last_changed( 'terms' );
    5068         }
    5069 
    5070         $this->query_cache_key = "wp_query:$key:$last_changed";
     5074        $this->query_cache_key = "wp_query:$key";
    50715075        return $this->query_cache_key;
    50725076    }
  • trunk/src/wp-includes/class-wp-site-query.php

    r59009 r60697  
    358358        $last_changed = wp_cache_get_last_changed( 'sites' );
    359359
    360         $cache_key   = "get_sites:$key:$last_changed";
    361         $cache_value = wp_cache_get( $cache_key, 'site-queries' );
     360        $cache_key   = "get_sites:$key";
     361        $cache_value = wp_cache_get_salted( $cache_key, 'site-queries', $last_changed );
    362362
    363363        if ( false === $cache_value ) {
     
    371371                'found_sites' => $this->found_sites,
    372372            );
    373             wp_cache_add( $cache_key, $cache_value, 'site-queries' );
     373            wp_cache_set_salted( $cache_key, $cache_value, 'site-queries', $last_changed );
    374374        } else {
    375375            $site_ids          = $cache_value['site_ids'];
  • trunk/src/wp-includes/class-wp-term-query.php

    r60661 r60697  
    778778
    779779        if ( $args['cache_results'] ) {
    780             $cache_key = $this->generate_cache_key( $args, $this->request );
    781             $cache     = wp_cache_get( $cache_key, 'term-queries' );
     780            $cache_key    = $this->generate_cache_key( $args, $this->request );
     781            $last_changed = wp_cache_get_last_changed( 'terms' );
     782            $cache        = wp_cache_get_salted( $cache_key, 'term-queries', $last_changed );
    782783
    783784            if ( false !== $cache ) {
     
    807808            $count = $wpdb->get_var( $this->request ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    808809            if ( $args['cache_results'] ) {
    809                 wp_cache_set( $cache_key, $count, 'term-queries' );
     810                wp_cache_set_salted( $cache_key, $count, 'term-queries', $last_changed );
    810811            }
    811812            return $count;
     
    816817        if ( empty( $terms ) ) {
    817818            if ( $args['cache_results'] ) {
    818                 wp_cache_add( $cache_key, array(), 'term-queries' );
     819                wp_cache_set_salted( $cache_key, array(), 'term-queries', $last_changed );
    819820            }
    820821            return array();
     
    901902
    902903        if ( $args['cache_results'] ) {
    903             wp_cache_add( $cache_key, $term_cache, 'term-queries' );
     904            wp_cache_set_salted( $cache_key, $term_cache, 'term-queries', $last_changed );
    904905        }
    905906
     
    11731174        $sql = $wpdb->remove_placeholder_escape( $sql );
    11741175
    1175         $key          = md5( serialize( $cache_args ) . $sql );
    1176         $last_changed = wp_cache_get_last_changed( 'terms' );
    1177         return "get_terms:$key:$last_changed";
     1176        $key = md5( serialize( $cache_args ) . $sql );
     1177
     1178        return "get_terms:$key";
    11781179    }
    11791180}
  • trunk/src/wp-includes/class-wp-user-query.php

    r59542 r60697  
    831831            $cache_key     = $this->generate_cache_key( $qv, $this->request );
    832832            $cache_group   = 'user-queries';
     833            $last_changed  = $this->get_cache_last_changed( $qv );
     834
    833835            if ( $qv['cache_results'] ) {
    834                 $cache_value = wp_cache_get( $cache_key, $cache_group );
     836                $cache_value = wp_cache_get_salted( $cache_key, $cache_group, $last_changed );
    835837            }
    836838            if ( false !== $cache_value ) {
     
    867869                        'total_users' => $this->total_users,
    868870                    );
    869                     wp_cache_add( $cache_key, $cache_value, $cache_group );
     871                    wp_cache_set_salted( $cache_key, $cache_value, $cache_group, $last_changed );
    870872                }
    871873            }
     
    10441046     *
    10451047     * @since 6.3.0
     1048     * @since 6.9.0 The `$args` parameter was deprecated and renamed to `$deprecated`.
    10461049     *
    10471050     * @global wpdb $wpdb WordPress database abstraction object.
    10481051     *
    1049      * @param array  $args Query arguments.
    1050      * @param string $sql  SQL statement.
     1052     * @param array  $deprecated Unused.
     1053     * @param string $sql        SQL statement.
    10511054     * @return string Cache key.
    10521055     */
    1053     protected function generate_cache_key( array $args, $sql ) {
     1056    protected function generate_cache_key( array $deprecated, $sql ) {
    10541057        global $wpdb;
    10551058
     
    10571060        $sql = $wpdb->remove_placeholder_escape( $sql );
    10581061
    1059         $key          = md5( $sql );
    1060         $last_changed = wp_cache_get_last_changed( 'users' );
     1062        $key = md5( $sql );
     1063
     1064        return "get_users:$key";
     1065    }
     1066
     1067    /**
     1068     * Retrieves the last changed cache timestamp for users and optionally posts.
     1069     *
     1070     * @since 6.9.0
     1071     *
     1072     * @param array $args Query arguments.
     1073     * @return string[] The last changed timestamp string for the relevant cache groups.
     1074     */
     1075    protected function get_cache_last_changed( array $args ) {
     1076        $last_changed = (array) wp_cache_get_last_changed( 'users' );
    10611077
    10621078        if ( empty( $args['orderby'] ) ) {
     
    10811097            }
    10821098
    1083             $last_changed .= wp_cache_get_last_changed( 'posts' );
     1099            $last_changed[] = wp_cache_get_last_changed( 'posts' );
    10841100
    10851101            if ( $switch ) {
     
    10881104        }
    10891105
    1090         return "get_users:$key:$last_changed";
     1106        return $last_changed;
    10911107    }
    10921108
  • trunk/src/wp-includes/general-template.php

    r60681 r60697  
    20702070        $query   = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
    20712071        $key     = md5( $query );
    2072         $key     = "wp_get_archives:$key:$last_changed";
    2073         $results = wp_cache_get( $key, 'post-queries' );
     2072        $key     = "wp_get_archives:$key";
     2073        $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
    20742074        if ( ! $results ) {
    20752075            $results = $wpdb->get_results( $query );
    2076             wp_cache_set( $key, $results, 'post-queries' );
     2076            wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
    20772077        }
    20782078        if ( $results ) {
     
    20952095        $query   = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
    20962096        $key     = md5( $query );
    2097         $key     = "wp_get_archives:$key:$last_changed";
    2098         $results = wp_cache_get( $key, 'post-queries' );
     2097        $key     = "wp_get_archives:$key";
     2098        $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
    20992099        if ( ! $results ) {
    21002100            $results = $wpdb->get_results( $query );
    2101             wp_cache_set( $key, $results, 'post-queries' );
     2101            wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
    21022102        }
    21032103        if ( $results ) {
     
    21192119        $query   = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
    21202120        $key     = md5( $query );
    2121         $key     = "wp_get_archives:$key:$last_changed";
    2122         $results = wp_cache_get( $key, 'post-queries' );
     2121        $key     = "wp_get_archives:$key";
     2122        $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
    21232123        if ( ! $results ) {
    21242124            $results = $wpdb->get_results( $query );
    2125             wp_cache_set( $key, $results, 'post-queries' );
     2125            wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
    21262126        }
    21272127        if ( $results ) {
     
    21452145        $query   = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
    21462146        $key     = md5( $query );
    2147         $key     = "wp_get_archives:$key:$last_changed";
    2148         $results = wp_cache_get( $key, 'post-queries' );
     2147        $key     = "wp_get_archives:$key";
     2148        $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
    21492149        if ( ! $results ) {
    21502150            $results = $wpdb->get_results( $query );
    2151             wp_cache_set( $key, $results, 'post-queries' );
     2151            wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
    21522152        }
    21532153        $arc_w_last = '';
     
    21842184        $query   = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
    21852185        $key     = md5( $query );
    2186         $key     = "wp_get_archives:$key:$last_changed";
    2187         $results = wp_cache_get( $key, 'post-queries' );
     2186        $key     = "wp_get_archives:$key";
     2187        $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
    21882188        if ( ! $results ) {
    21892189            $results = $wpdb->get_results( $query );
    2190             wp_cache_set( $key, $results, 'post-queries' );
     2190            wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
    21912191        }
    21922192        if ( $results ) {
  • trunk/src/wp-includes/link-template.php

    r60269 r60697  
    20062006    $query        = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
    20072007    $key          = md5( $query );
    2008     $last_changed = wp_cache_get_last_changed( 'posts' );
     2008    $last_changed = (array) wp_cache_get_last_changed( 'posts' );
    20092009    if ( $in_same_term || ! empty( $excluded_terms ) ) {
    2010         $last_changed .= wp_cache_get_last_changed( 'terms' );
    2011     }
    2012     $cache_key = "adjacent_post:$key:$last_changed";
    2013 
    2014     $result = wp_cache_get( $cache_key, 'post-queries' );
     2010        $last_changed[] = wp_cache_get_last_changed( 'terms' );
     2011    }
     2012    $cache_key = "adjacent_post:$key";
     2013
     2014    $result = wp_cache_get_salted( $cache_key, 'post-queries', $last_changed );
    20152015    if ( false !== $result ) {
    20162016        if ( $result ) {
     
    20252025    }
    20262026
    2027     wp_cache_set( $cache_key, $result, 'post-queries' );
     2027    wp_cache_set_salted( $cache_key, $result, 'post-queries', $last_changed );
    20282028
    20292029    if ( $result ) {
  • trunk/src/wp-includes/post.php

    r60621 r60697  
    61056105
    61066106    $hash      = md5( $page_path . serialize( $post_type ) );
    6107     $cache_key = "get_page_by_path:$hash:$last_changed";
    6108     $cached    = wp_cache_get( $cache_key, 'post-queries' );
     6107    $cache_key = "get_page_by_path:$hash";
     6108    $cached    = wp_cache_get_salted( $cache_key, 'post-queries', $last_changed );
    61096109    if ( false !== $cached ) {
    61106110        // Special case: '0' is a bad `$page_path`.
     
    61766176
    61776177    // We cache misses as well as hits.
    6178     wp_cache_set( $cache_key, $found_id, 'post-queries' );
     6178    wp_cache_set_salted( $cache_key, $found_id, 'post-queries', $last_changed );
    61796179
    61806180    if ( $found_id ) {
  • trunk/src/wp-includes/query.php

    r56434 r60697  
    11561156    $key          = md5( $query );
    11571157    $last_changed = wp_cache_get_last_changed( 'posts' );
    1158     $cache_key    = "find_post_by_old_slug:$key:$last_changed";
    1159     $cache        = wp_cache_get( $cache_key, 'post-queries' );
     1158    $cache_key    = "find_post_by_old_slug:$key";
     1159    $cache        = wp_cache_get_salted( $cache_key, 'post-queries', $last_changed );
    11601160    if ( false !== $cache ) {
    11611161        $id = $cache;
    11621162    } else {
    11631163        $id = (int) $wpdb->get_var( $query );
    1164         wp_cache_set( $cache_key, $id, 'post-queries' );
     1164        wp_cache_set_salted( $cache_key, $id, 'post-queries', $last_changed );
    11651165    }
    11661166
     
    11991199        $key          = md5( $query );
    12001200        $last_changed = wp_cache_get_last_changed( 'posts' );
    1201         $cache_key    = "find_post_by_old_date:$key:$last_changed";
    1202         $cache        = wp_cache_get( $cache_key, 'post-queries' );
     1201        $cache_key    = "find_post_by_old_date:$key";
     1202        $cache        = wp_cache_get_salted( $cache_key, 'post-queries', $last_changed );
    12031203        if ( false !== $cache ) {
    12041204            $id = $cache;
     
    12091209                $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id AND post_type = %s AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, $post_type, get_query_var( 'name' ) ) );
    12101210            }
    1211             wp_cache_set( $cache_key, $id, 'post-queries' );
     1211            wp_cache_set_salted( $cache_key, $id, 'post-queries', $last_changed );
    12121212        }
    12131213    }
  • trunk/src/wp-includes/taxonomy.php

    r60676 r60697  
    897897
    898898    $last_changed = wp_cache_get_last_changed( 'terms' );
    899     $cache_key    = 'get_objects_in_term:' . md5( $sql ) . ":$last_changed";
    900     $cache        = wp_cache_get( $cache_key, 'term-queries' );
     899    $cache_key    = 'get_objects_in_term:' . md5( $sql );
     900    $cache        = wp_cache_get_salted( $cache_key, 'term-queries', $last_changed );
    901901    if ( false === $cache ) {
    902902        $object_ids = $wpdb->get_col( $sql );
    903         wp_cache_set( $cache_key, $object_ids, 'term-queries' );
     903        wp_cache_set_salted( $cache_key, $object_ids, 'term-queries', $last_changed );
    904904    } else {
    905905        $object_ids = (array) $cache;
  • trunk/src/wp-includes/user.php

    r60650 r60697  
    624624
    625625    $last_changed = wp_cache_get_last_changed( 'posts' );
    626     $cache_key    = 'count_user_posts:' . md5( $query ) . ':' . $last_changed;
    627     $count        = wp_cache_get( $cache_key, 'post-queries' );
     626    $cache_key    = 'count_user_posts:' . md5( $query );
     627    $count        = wp_cache_get_salted( $cache_key, 'post-queries', $last_changed );
    628628    if ( false === $count ) {
    629629        $count = $wpdb->get_var( $query );
    630         wp_cache_set( $cache_key, $count, 'post-queries' );
     630        wp_cache_set_salted( $cache_key, $count, 'post-queries', $last_changed );
    631631    }
    632632
  • trunk/tests/phpunit/tests/functions/wpCacheSetLastChanged.php

    r57733 r60697  
    11<?php
     2
    23/**
    34 * Tests for the wp_cache_set_last_changed() function.
    45 *
    56 * @group functions
     7 * @group cache
    68 *
    79 * @covers ::wp_cache_set_last_changed
Note: See TracChangeset for help on using the changeset viewer.