[wp-trac] [WordPress Trac] #14992: When Object Caching is enabled switch_to_blog causes issues with some functions
WordPress Trac
wp-trac at lists.automattic.com
Wed Sep 29 20:19:08 UTC 2010
#14992: When Object Caching is enabled switch_to_blog causes issues with some
functions
---------------------------+------------------------------------------------
Reporter: simonwheatley | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Multisite | Version:
Severity: normal | Keywords: dev-feedback
---------------------------+------------------------------------------------
When you use {{{switch_to_blog}}} with an Object caching plugin installed
you get incorrect links from {{{home_url}}} and therefore also
{{{get_permalink}}}.
To reproduce:
1. Setup a WP Network using sub-directories with at least two sites
2. Install an Object caching plugin
3. Assuming that {{{get_option}}} has been called earlier, thereby
loading the cache with {{{alloptions}}}, use {{{switch_to_blog}}} then
{{{get_permalink}}}
4. {{{get_permalink}}} returns a URL based on the site which was active
'''before''' you used {{{switch_to_blog}}}
The problem seems to be that the Object cache caches {{{alloptions}}}, but
these aren't refreshed or switched when {{{switch_to_blog}}} is used (at
this point a new set of options should be made available).
I'm using this code to get around it (this is not a patch, obviously):
{{{
/**
* Hooks the WP MS action switch_blog to switch some caches cache when a
blog
* is switched to.
*
* @param int $blog_id The ID of the blog which has been switched to
* @param int $prev_blog_id The ID of the blog we were in before switching
* @return void
**/
function kcostb_switch_blog( $blog_id, $prev_blog_id ) {
// Save the previous alloptions cache
$prev_alloptions = wp_cache_get( 'alloptions', 'options' );
// Do we have a previously cached alloptions for the new blog? If
so,
// replace the current alloptions cache otherwise delete it.
if ( $alloptions = wp_cache_get( "alloptions_$blog_id", 'options'
) )
wp_cache_replace( "alloptions", $alloptions, 'options' );
else
wp_cache_delete( 'alloptions', 'options' );
}
add_action( 'switch_blog', 'kcostb_switch_blog', null, 2 );
}}}
Questions:
* Should this be solved by switching caches (as my mini plugin does)?
* Should we simply delete the {{{alloptions}}} cache when
{{{switch_to_blog}}} is used?
* Are there any other areas affected similarly?
Happy to produce a patch if the first two questions could be advised upon.
Could be related to #12040
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14992>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list