Created
December 10, 2012 23:19
-
-
Save westonruter/4254249 to your computer and use it in GitHub Desktop.
Patch for WP Memcached Object Cache to make key generation dynamic instead of static; fixes problems with switch_to_blog()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/wp-content/object-cache.php | |
+++ b/wp-content/object-cache.php | |
@@ -263,10 +263,18 @@ class WP_Object_Cache { | |
if ( empty($group) ) | |
$group = 'default'; | |
+ global $blog_id, $table_prefix; | |
+ $global_prefix = ''; | |
+ $blog_prefix = ''; | |
+ if ( function_exists( 'is_multisite' ) ) { | |
+ $global_prefix = ( is_multisite() || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ) ? '' : $table_prefix; | |
+ $blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':'; | |
+ } | |
+ | |
if ( false !== array_search($group, $this->global_groups) ) | |
- $prefix = $this->global_prefix; | |
+ $prefix = $global_prefix; | |
else | |
- $prefix = $this->blog_prefix; | |
+ $prefix = $blog_prefix; | |
return preg_replace('/\s+/', '', WP_CACHE_KEY_SALT . "$prefix$group:$key"); | |
} | |
@@ -382,14 +390,6 @@ class WP_Object_Cache { | |
} | |
} | |
- global $blog_id, $table_prefix; | |
- $this->global_prefix = ''; | |
- $this->blog_prefix = ''; | |
- if ( function_exists( 'is_multisite' ) ) { | |
- $this->global_prefix = ( is_multisite() || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ) ? '' : $table_prefix; | |
- $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':'; | |
- } | |
- | |
$this->cache_hits =& $this->stats['get']; | |
$this->cache_misses =& $this->stats['add']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Posted writeup to WordPress plugin forum: http://wordpress.org/support/topic/issue-with-multisite-and-use-of-switch_to_blog?replies=1#post-3541617