[wp-trac] [WordPress Trac] #57625: WP_Query cache memory leak

WordPress Trac noreply at wordpress.org
Tue Feb 7 18:08:51 UTC 2023


#57625: WP_Query cache memory leak
--------------------------+------------------------------
 Reporter:  owi           |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Cache API     |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  performance
--------------------------+------------------------------

Comment (by tillkruess):

 Having a filter like `wp_cache_set_posts_last_changed` would allow expired
 cache keys to be invalidated atomically (or be queued for deletion). A bit
 annoying to implement, but easy to add in core.

 Something less annoying would be a better API.

 {{{#!php
 <?php
 $key          = md5( $query );
 $last_changed = wp_cache_get_last_changed( 'posts' );

 // current implementation
 $cache_key    = "find_post_by_old_slug:$key:$last_changed";
 $cache        = wp_cache_get( $cache_key, 'posts' );

 // better approach
 $cache_key    = "find_post_by_old_slug:$key";
 $cache        = wp_cache_get_latest( $cache_key, 'posts', $last_changed );
 }}}

 That would allow plugins like Redis Object Cache or Object Cache Pro to
 invalidate more efficiently and on the fly.

 The `"find_post_by_old_slug:$key"` could be a hash map, so the entire
 cache's keyspace doesn't need to be scanned, which is always slow.

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


More information about the wp-trac mailing list