WordPress.org

Support

Support » Plugins and Hacks » Issue with multisite and use of switch_to_blog()

Issue with multisite and use of switch_to_blog()

  • I’m working on a multisite instance which includes some cross-posting functionality, allowing you to publish a post on one blog and then to have a that same post shallow-copy onto other blogs on the network. When this shallow copy is rendered on the other blogs, it wraps the_content() in calls to switch_to_blog($original_blog_id)/restore_current_blog() so that galleries and other shortcodes will continue to function as they do on the original blog. I encountered issues with this functionality when Memcached Object Cache is enabled.

    The issue seems to be that the $blog_prefix and $global_prefix are defined once upon initialization instead of when the cache key is generated, so that once switch_to_blog() is called the cache key is not valid anymore. I fixed the issue by determining $blog_prefix and $global_prefix at runtime when the key() method is called. This ensures that the $blog_id used in the prefixes is proper.

    I also patched it so that the $blog_id is added even to the $global_prefix, just to make certain that the caches the blogs would not pollute each other.

    Lastly, I fixed some apparently broken logic surrounding the incorporation of WP_CACHE_KEY_SALT. It seemed the closing paren for preg_replace was misplaced.

    See patch: https://gist.github.com/4254249

    http://wordpress.org/extend/plugins/memcached/

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Issue with multisite and use of switch_to_blog()’ is closed to new replies.