[wp-trac] [WordPress Trac] #40171: Object Cache Should Support Namespaces

WordPress Trac noreply at wordpress.org
Thu Mar 16 12:56:06 UTC 2017


#40171: Object Cache Should Support Namespaces
--------------------------+-----------------------------
 Reporter:  brandonliles  |      Owner:
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.2
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 Currently if any code (particularly a plugin) needs to delete many
 different cache keys, the default solution is to call wp_cache_flush().
 However, this flushes the global cache which may cause serious performance
 issues on a live site since it affects all cached data. Furthermore is it
 probably an extremely rare case that all cached data needs to be purged
 rather than a subset.

 Solution Summary: Support namespaces on wp cache calls so that it is
 possible to kill ranges of cache keys without flushing the entire cache.

 Design:
 1. Cache functions have an optional parameter added to specify cache
 namespace. The default namespace will resolve to the global cache.
 2. An int value is tracked for each namespace. The current int values for
 each namespace can be stored in the object cache.
 3. When a caller performs a get/set the current int value for the
 specified namespace is obtained and the namespace + int value is prepended
 to the key provided by the caller.
 4. When all cache keys within a namespace need to be cleared, the int
 value for that namespace is incremented, and all subsequent get/sets will
 begin using new keys. Memcache will eventually purge the old data.

 This adds the slight overhead of maintaining the int values for each
 namespace but allows selectively killing/invalidating cache keys without
 flushing the entire cache. If necessary namespace values can be statically
 cached to avoid getting the same namespace value from memcache several
 times.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40171>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list