[wp-trac] [WordPress Trac] #59592: Store last changed value in key instead of using it as a salt for query caches

WordPress Trac noreply at wordpress.org
Mon Aug 25 21:57:17 UTC 2025


#59592: Store last changed value in key instead of using it as a salt for query
caches
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:
                                                 |  spacedmonkey
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.9
Component:  Cache API                            |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-dev-  |     Focuses:
  note                                           |  performance
-------------------------------------------------+-------------------------

Comment (by peterwilsoncc):

 Brain dump follows. I think any of the suggestions are good enough.

 ----


 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59592#comment:53>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list