[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
Fri Aug 22 21:24:36 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 spacedmonkey):

 I am really struggling with the commit message for this change. This is
 what I have so far.

 Caching API: Add new helper functions for query-based caches

 Query-based caches are now improved by reusing cache keys. On high-traffic
 sites, the last_changed value can change frequently for user cache groups
 such as posts or terms. 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, a new cache key (and cache entry) was
 generated, while the old cache was left to expire naturally in the object
 cache.

 That approach relied on the object cache backend efficiently evicting
 stale caches. This worked well with memcache, but with other backends such
 as Redis, eviction behaviour is not always reliable.

 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.

 Love feedback @peterwilsoncc @tillkruess @flixos90

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


More information about the wp-trac mailing list