[wp-trac] [WordPress Trac] #62476: Need the ability to clear WP_Query cache partially and ability to set expiry for queries.

WordPress Trac noreply at wordpress.org
Mon Jan 6 11:34:14 UTC 2025


#62476: Need the ability to clear WP_Query cache partially and ability to set
expiry for queries.
-------------------------+------------------------------------------
 Reporter:  thekt12      |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |     Focuses:  performance, sustainability
-------------------------+------------------------------------------

Comment (by vineet2003):

 I’ve been following the conversation around WP_Query caching, and I
 appreciate the feedback and insights shared by @joemcgill and others
 during the Performance bug scrub.

 The primary challenge here is that WordPress currently lacks flexibility
 when it comes to caching WP_Query results. This limitation makes it
 difficult to selectively clear cached data and manage cache expiration
 times effectively, which can cause performance bottlenecks, especially on
 high-traffic sites.
 The goal is to introduce a more granular caching system that allows
 developers to:

     1. Selectively clear cache entries for specific queries or groups of
 queries.
     2. Set custom cache expiration times for different queries.
     3. Ensure performance is improved without compromising cache
 integrity.

 To address these needs, I propose the following enhancements to WP_Query
 caching:

 1. Selective Cache Flushing via Action Hooks: Introduce an action like
 wp_query_cache_key_generated to allow developers to hook into the cache
 key generation process, enabling targeted cache invalidation for specific
 queries or groups.

 2. Custom Cache Groups: Allow developers to assign custom cache group
 names via query arguments (e.g., 'cache_group' => 'category_news') to
 group related queries together for easier cache management and
 invalidation.
 3. Custom Cache Expiry: Introduce a cache_expiry argument for WP_Query,
 which will allow developers to set custom expiration times for cached
 results, reducing the need for manual cache clearing and ensuring data
 freshness.

 I’d be happy to take on the implementation of this solution and contribute
 a patch for review.
 If there are any additional concerns or suggestions, I’m open to
 collaborating further to ensure that this solution meets the requirements
 and is aligned with the best practices of WordPress development.

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


More information about the wp-trac mailing list