[wp-trac] [WordPress Trac] #59516: Improve cache key generation in the WP_Query class (was: Improve cache key generation in query classes)

WordPress Trac noreply at wordpress.org
Thu Jan 23 22:15:19 UTC 2025


#59516: Improve cache key generation in the WP_Query class
-----------------------------------------------+--------------------------
 Reporter:  spacedmonkey                       |       Owner:  pbearne
     Type:  defect (bug)                       |      Status:  accepted
 Priority:  normal                             |   Milestone:  6.8
Component:  Query                              |     Version:
 Severity:  normal                             |  Resolution:
 Keywords:  has-patch changes-requested early  |     Focuses:  performance
-----------------------------------------------+--------------------------
Description changed by peterwilsoncc:

Old description:

> In query classes such as WP_Query, parameters like post_type enable the
> passing of an array of values. For instance, you can use post_type like
> this: ['post', 'page']. However, if a subsequent request is made with the
> array elements in a different order, like so: ['page', 'post'], it would
> lead to the generation of a different cache key, potentially causing the
> existing cache to be missed. Even though the cached results may be the
> same, this could result in a cache collision. It is advisable to reuse
> caches whenever possible to optimize performance.
>
> This would effect the following cache keys.
>
> - WP_Query
> - WP_Term_Query
> - WP_Network_Query
> - WP_Site_Query
> - WP_Comment_Query
>
> Some sort of array sorting of the key values would mean that caches could
> be reused.

New description:

 In WP_Query, parameters like post_type enable the passing of an array of
 values. For instance, you can use post_type like this: ['post', 'page'].
 However, if a subsequent request is made with the array elements in a
 different order, like so: ['page', 'post'], it would lead to the
 generation of a different cache key, potentially causing the existing
 cache to be missed. Even though the cached results may be the same, this
 could result in a cache collision. It is advisable to reuse caches
 whenever possible to optimize performance.

 Some sort of array sorting of the key values would mean that caches could
 be reused.

 Similar optimization can be done in other Query classes to improve cache
 hits on follow up tickets.

 - WP_Term_Query
 - WP_Network_Query
 - WP_Site_Query
 - WP_Comment_Query

 ----

 Edited 24 Jan, 2025 to focus this ticket on WP_Query per [comment:31
 comments #31] thru #33.

--

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


More information about the wp-trac mailing list