WordPress.org

Make WordPress Core

Opened 6 weeks ago

#54303 new enhancement

[Object Cache] Allow global caching groups to be filterable / changed

Reported by: janthiel Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.8.1
Component: Cache API Keywords: dev-feedback needs-patch
Focuses: multisite Cc:

Description

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.
  1. Add a function to the Object Cache API to actually remove cache groups from the globals list.
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.

  1. 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+
  1. 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 :-)

Change History (0)

Note: See TracTickets for help on using tickets.