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: https://develop.svn.wordpress.org/trunk@21403 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2012-08-02 18:31:14 +00:00
parent ecd9fe3d78
commit 691425a3ff
3 changed files with 115 additions and 38 deletions

View File

@@ -381,7 +381,7 @@ function wp_set_wpdb_vars() {
* @since 3.0.0
*/
function wp_start_object_cache() {
global $_wp_using_ext_object_cache;
global $_wp_using_ext_object_cache, $blog_id;
$first_init = false;
if ( ! function_exists( 'wp_cache_init' ) ) {
@@ -403,8 +403,8 @@ function wp_start_object_cache() {
// If cache supports reset, reset instead of init if already initialized.
// Reset signals to the cache that global IDs have changed and it may need to update keys
// and cleanup caches.
if ( !$first_init && function_exists('wp_cache_reset') )
wp_cache_reset();
if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
wp_cache_switch_to_blog( $blog_id );
else
wp_cache_init();