Introduce wp_cache_switch_to_blog() and WP_Object_Cache::switch_to_blog() as a lighter/faster way to switch the cache to a new blog id.
Add the blog id to the cache keys for multisite installs. Use wp_cache_switch_to_blog() instead of wp_cache_init() in switch_to_blog(). Use wp_cache_switch_to_blog() instead of wp_cache_reset() in wp_start_object_cache(). Deprecate wp_cache_reset(). This avoids the many queries needed to re-prime the cache after switch_to_blog() on multisite installs using the default cache backend. fixes #21434 git-svn-id: http://core.svn.wordpress.org/trunk@21403 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -487,18 +487,22 @@ function switch_to_blog( $new_blog, $validate = false ) {
|
||||
$current_user->for_blog( $blog_id );
|
||||
}
|
||||
|
||||
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
|
||||
$global_groups = $wp_object_cache->global_groups;
|
||||
else
|
||||
$global_groups = false;
|
||||
|
||||
wp_cache_init();
|
||||
if ( function_exists('wp_cache_add_global_groups') ) {
|
||||
if ( is_array( $global_groups ) )
|
||||
wp_cache_add_global_groups( $global_groups );
|
||||
if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
|
||||
wp_cache_switch_to_blog( $blog_id );
|
||||
} else {
|
||||
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
|
||||
$global_groups = $wp_object_cache->global_groups;
|
||||
else
|
||||
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
|
||||
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
|
||||
$global_groups = false;
|
||||
|
||||
wp_cache_init();
|
||||
if ( function_exists('wp_cache_add_global_groups') ) {
|
||||
if ( is_array( $global_groups ) )
|
||||
wp_cache_add_global_groups( $global_groups );
|
||||
else
|
||||
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
|
||||
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
|
||||
}
|
||||
}
|
||||
|
||||
do_action('switch_blog', $blog_id, $prev_blog_id);
|
||||
@@ -551,18 +555,22 @@ function restore_current_blog() {
|
||||
$current_user->for_blog( $blog_id );
|
||||
}
|
||||
|
||||
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
|
||||
$global_groups = $wp_object_cache->global_groups;
|
||||
else
|
||||
$global_groups = false;
|
||||
|
||||
wp_cache_init();
|
||||
if ( function_exists('wp_cache_add_global_groups') ) {
|
||||
if ( is_array( $global_groups ) )
|
||||
wp_cache_add_global_groups( $global_groups );
|
||||
if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
|
||||
wp_cache_switch_to_blog( $blog_id );
|
||||
} else {
|
||||
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
|
||||
$global_groups = $wp_object_cache->global_groups;
|
||||
else
|
||||
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
|
||||
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
|
||||
$global_groups = false;
|
||||
|
||||
wp_cache_init();
|
||||
if ( function_exists('wp_cache_add_global_groups') ) {
|
||||
if ( is_array( $global_groups ) )
|
||||
wp_cache_add_global_groups( $global_groups );
|
||||
else
|
||||
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
|
||||
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
|
||||
}
|
||||
}
|
||||
|
||||
do_action('switch_blog', $blog_id, $prev_blog_id);
|
||||
|
||||
Reference in New Issue
Block a user