wp_cache_switch_to_blog_fallback()
- Since
- 7.0.0
- Source
wp-includes/ms-blogs.php:611
Description
Reinitializes the cache and restores global/non-persistent groups.
Used by the wp_cache_switch_to_blog() compatibility function, abstracted only to allow for unit testing outside of the drop-in plugin inclusion circus.
Compatibility
- WordPress
- since 7.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to wp_cache_switch_to_blog_fallback() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Constant
- Instructions
- 16–72
- Plugin surface
- None
- Called by
- 1
Only touches the object cache, via wp_cache_switch_to_blog_fallback().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 74.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_switch_to_blog_fallback()this function does it
What one call costs · 20 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_cache_switch_to_blog_fallback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!function_exists() | 16–21 | wp_cache_init(), function_exists(), function_exists() |
| always | 22–29 | wp_cache_init(), function_exists(), function_exists(), wp_cache_add_non_persistent_groups() |
| always | 22–29 | wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists() |
function_exists() | 28–37 | wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() && !function_exists() | 31–39 | wp_is_numeric_array(), wp_cache_init(), function_exists(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() && !function_exists() | 35–43 | wp_is_numeric_array(), array_keys(), wp_cache_init(), function_exists(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() | 37–47 | wp_is_numeric_array(), wp_cache_init(), function_exists(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() | 37–47 | wp_is_numeric_array(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() | 41–51 | wp_is_numeric_array(), array_keys(), wp_cache_init(), function_exists(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() | 41–51 | wp_is_numeric_array(), array_keys(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() && function_exists() | 43–55 | wp_is_numeric_array(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() && !function_exists() | 47–52 | wp_is_numeric_array(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), function_exists() |
8 further outcomes, up to 72 instructions
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() && function_exists() | 47–59 | wp_is_numeric_array(), array_keys(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() && !function_exists() | 51–56 | wp_is_numeric_array(), array_keys(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() | 53–60 | wp_is_numeric_array(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() | 53–60 | wp_is_numeric_array(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() | 57–64 | wp_is_numeric_array(), array_keys(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() | 57–64 | wp_is_numeric_array(), array_keys(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists() |
is_object($wp_object_cache) && isset($wp_object_cache) && wp_is_numeric_array() && function_exists() | 59–68 | wp_is_numeric_array(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists(), wp_cache_add_non_persistent_groups() |
is_object($wp_object_cache) && isset($wp_object_cache) && !wp_is_numeric_array() && function_exists() | 63–72 | wp_is_numeric_array(), array_keys(), array_keys(), array_diff(), array_values(), wp_cache_init(), function_exists(), wp_cache_add_global_groups(), function_exists(), wp_cache_add_non_persistent_groups() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 74 instructions, 16–72 executed per call, 15 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 4
- wp_is_numeric_array()Determines if the variable is a numeric-indexed array.
- wp_cache_init()Sets up Object Cache Global and assigns it.
- wp_cache_add_global_groups()Adds a group or set of groups to the list of global groups.
- wp_cache_add_non_persistent_groups()Adds a group or set of groups to the list of non-persistent groups.
Used by · 1
- wp_cache_switch_to_blog()Used when switch_to_blog() and restore_current_blog() are called, but only when a persistent object cache drop-in plugin has omitted the wp_cache_switch_to_blog() function that was introduced in 3.5.0.
Source code
function wp_cache_switch_to_blog_fallback() { global $wp_object_cache; $global_groups = false; $non_persistent_groups = false; if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) && is_array( $wp_object_cache->global_groups ) ) { // Get the global groups as they are. $group_names = $wp_object_cache->global_groups; // Get global group keys if non-numeric array. if ( ! wp_is_numeric_array( $group_names ) ) { $group_names = array_keys( $group_names ); } $global_groups = $group_names; /* * Non-persistent groups: Check for no_mc_groups first (memcached drop-in). * Fall back to cache structure (default cache). */ if ( isset( $wp_object_cache->no_mc_groups ) && is_array( $wp_object_cache->no_mc_groups ) && ! empty( $wp_object_cache->no_mc_groups ) ) { $non_persistent_groups = $wp_object_cache->no_mc_groups; } elseif ( isset( $wp_object_cache->cache ) && is_array( $wp_object_cache->cache ) ) { $all_groups = array_keys( $wp_object_cache->cache ); $non_persistent_groups = array_values( array_diff( $all_groups, $global_groups ) ); } } wp_cache_init(); if ( function_exists( 'wp_cache_add_global_groups' ) ) { if ( ! is_array( $global_groups ) || empty( $global_groups ) ) { $global_groups = array( 'blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'image_editor', 'networks', 'network-queries', 'sites', 'site-details', 'site-options', 'site-queries', 'site-transient', 'theme_files', 'translation_files', 'rss', 'users', 'user-queries', 'user_meta', 'useremail', 'userlogins', 'userslugs', ); } wp_cache_add_global_groups( $global_groups ); } if ( function_exists( 'wp_cache_add_non_persistent_groups' ) ) { if ( ! is_array( $non_persistent_groups ) || empty( $non_persistent_groups ) ) { $non_persistent_groups = array( 'counts', 'plugins', 'theme_json', ); } wp_cache_add_non_persistent_groups( $non_persistent_groups ); }}Changelog
Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/ms-blogs.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.