Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created December 10, 2012 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/4254249 to your computer and use it in GitHub Desktop.
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()
--- 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'];
}
@westonruter
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment