public
Last active

Patch for WP Memcached Object Cache to make key generation dynamic instead of static; fixes problems with switch_to_blog()

  • Download Gist
object-cache.php.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
--- 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'];
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.