[wp-trac] [WordPress Trac] #54303: [Object Cache] Allow global caching groups to be filterable / changed

WordPress Trac noreply at wordpress.org
Thu Oct 21 13:02:06 UTC 2021


#54303: [Object Cache] Allow global caching groups to be filterable / changed
-------------------------+--------------------------------------
 Reporter:  janthiel     |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Cache API    |    Version:  5.8.1
 Severity:  minor        |   Keywords:  dev-feedback needs-patch
  Focuses:  multisite    |
-------------------------+--------------------------------------
 The Object Caching system differentiates between "local cache groups" and
 "global cache groups". This is essential for Multisite setups.

 Global cache groups store cached objects - as the name implies - globally.
 There is one cached object for all sites in the network. Whereas the local
 cache groups are stored individually per site.

 The cache groups are setup using the {{{wp_cache_...}}} API. Like
 https://developer.wordpress.org/reference/functions/wp_cache_add/

 Which groups are actually global is setup in the Object Cache
 bootstrapping code here:

 https://github.com/WordPress/WordPress/blob/e791d7f5db8252ba66c7777c456ed80343a450aa
 /wp-includes/load.php#L732-L735
 {{{
 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta',
 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options',
 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts',
 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) );
 }}}
 This is hardcoded and not filterable in any (reasonable) way. Currently
 you have to rely on the actual Object Caching implementation to allow one
 to change the global cache groups.

 The current globals setup is fine for the assumption of a default
 WordPress installation. But as it is with customizable software like
 WordPress, this is not true in any case.

 For example: If one would split the user information and move it from the
 (global) network level to the individual sites, one would have to remove
 all the user related groups from the global cache groups.

 This is currently not possible at all.

 There are some possible solutions:

 1. Make the array of global cache groups filtereable
 - This might be a timing issue because the object cache system is loaded
 very early. But it might work.

 2. Add a function to the Object Cache API to actually remove cache groups
 from the globals list.
 - This is the {{{add}}} function:
 https://developer.wordpress.org/reference/classes/wp_object_cache/add_global_groups/
 - This could be extended with a counterpart:

 {{{
 public function remove_global_groups( $groups ) {
     $groups = (array) $groups;

     $this->global_groups = array_diff_key( $this->global_groups, $groups
 );
 }
 }}}
 This could then be leveraged from plugins at any point of time. Yet it
 still might kick in too late due to the early nature of the object cache
 system.

 3. If timing issues are an issue, instead of the filters, one could make
 the filtering available using a constant (
 WP_OBJECT_CACHE_NON_GLOBAL_GROUPS => array( 'users', 'usermeta' ) ). Yet
 this depends on PHP7+

 4. Configure the global cachegroups late when filters are available and
 allow default WP filtering

 Is this an Edge case? Yes! But it still is quite a burden on the
 flexibility of the Object cache that could be solved :-)

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


More information about the wp-trac mailing list