wp_cache_add_global_groups()WP 2.6.0

Adds the specified object cache group to the list of global groups. Needed for multisite.

Global cache groups are groups for which a blog prefix is not set, and a single cache works for the entire network.

How it works

When adding object cache via the function wp_cache_add( $key, $data, $group ), you can specify a group in the third parameter. If this group is global, then the cache will be the same for all sites in the network. If not, the cache will differ - each site in the network will have its own cache.

By default, the global groups are:

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

If you need the object cache to not work at all for the specified group, use the function wp_cache_add_non_persistent_groups().

No Hooks.

Returns

null. Nothing (null)

Usage

wp_cache_add_global_groups( $groups );
$groups(string/array) (required)
The name of the group or an array of group names to mark as global.

Examples

0

#1 Example of adding a global group

Suppose we have created an entity with its own table in the database and a separate table with metadata. The entity is called 'tests'. The metadata is controlled by WP functions: add_metadata(), get_metadata() etc.

Now, we need to make the data stored in the cache of this entity be the same for the whole sites network, not different for different sites in the network. To do this, let's create the global group tests_meta (group is specified when adding the metadata cache).

wp_cache_add_global_groups( 'tests_meta' );

Now when adding or retrieve data using add_metadata( 'tests', ... ) and get_metadata( 'tests', ... ) the cache will be the same among all sites in Multisite network.

Notes

Changelog

Since 2.6.0 Introduced.

wp_cache_add_global_groups() code WP 6.9.1

function wp_cache_add_global_groups( $groups ) {
	global $wp_object_cache;

	$wp_object_cache->add_global_groups( $groups );
}