WordPress.org

Ready to get started?Download WordPress

Forums

Memcached Object Cache
Issue with multisite and use of switch_to_blog() (7 posts)

  1. Weston Ruter
    Member
    Posted 1 year ago #

    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/

  2. Weston Ruter
    Member
    Posted 1 year ago #

    This was invalid:

    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.

    I misread the original line. I've updated the gist to remove the change to the patch.

  3. Weston Ruter
    Member
    Posted 1 year ago #

    This specific change was also invalid:

    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.

    When used with Batcache, for example, the $blog_id when advanced-cache runs is actually 1 instead of the actual ID for the current blog. But when Batcache (for example) saves the page into the cache, the $blog_id is then set. So the end result is that there were never any cache HITs only cache MISSes.

  4. Weston Ruter
    Member
    Posted 1 year ago #

    The Gist patch has been updated: https://gist.github.com/4254249

  5. Weston Ruter
    Member
    Posted 1 year ago #

    And it actually seems this switch_to_blog issue is on the radar because there was a commit a few weeks ago specifically for it: http://plugins.trac.wordpress.org/changeset?reponame=&new=626248%40memcached%2Ftrunk%2Fobject-cache.php&old=539529%40memcached%2Ftrunk%2Fobject-cache.php

  6. tonny@debug.dk
    Member
    Posted 1 year ago #

  7. Weston Ruter
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic