Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im running a rather large wpmu setup bloggersdelight.dk - from time to time, we need to reset the object cache when doing changes on the site. When we do this, things mess up. Option values from sites gets mixed together and homeurls for blogs redirects to wrong blogs etc.

This is the current object-cache.php im working with.

http://pastebin.com/QgM5tR9n

As you can se the flush function is created in a way that it does not allow to flush if multisite. This was the default for the plugin found on wordpress.org. In order to flush a blogs cache i need to do some "fun" created stuff like this:

switch_to_blog($blogid);

$pattern = "/^" . $blogid . ":/";

$memcache = new Memcache();
$memcache->connect( $server, $port );

$list = array();
$allSlabs = $memcache->getExtendedStats( 'slabs' );
$items = $memcache->getExtendedStats( 'items' );
foreach ( $allSlabs as $server => $slabs ) {
foreach( $slabs as $slabId => $slabMeta ) {
if ( !empty( $slabId ) ) {
$cdump = $memcache->getExtendedStats( 'cachedump', (int) $slabId );
foreach( $cdump as $keys => $arrVal ) {
if ( !is_array( $arrVal ) ) continue;
foreach( $arrVal as $k => $v ) {
if(preg_match($pattern, $k))
{
$list[] = $k;
# $memcache->delete($k);
$parts = explode(":",$k);
print_r($parts);

wp_cache_delete($parts[2],$parts[1]);

}
}
}
}
}
}
return $list;

This seems to work for a single blog, allthough some items do not get cleared.

Anyways, the problems occour when i do this

telnet localhost 11211 and then type flush_all

then things get weird and option values get mixed between blogs. If i run the flush_all command multiplte times then the problem usually is reducd and less blogs gets wrong option values.

Does anyone have any suggestion to how to solve this ?

Do i need to create some kind of key SALT ?

share|improve this question
add comment

2 Answers 2

Are you running WordPress 3.5? If not, you should try upgrading because the stability of the blog-switching functionality has been greatly improved in this version:

Multisite's switch_to_blog() is now significantly faster and more reliable

Once you have done this, try using the trunk version of the Memcached Object Cache plugin which adds support for the new blog-switching performance enhancements in WordPress 3.5:

Add support for wp_cache_switch_to_blog().

We were experiencing similar problems with switch_to_blog() and Memcached Object Cache in WordPress 3.4, and making the above changes resolved the problems in our case.

share|improve this answer
    
Im running 3.4.2 at the moment... it seems like alot of blogs are getting option values from main blog.. This is why i suspect eight switch_to_blog to have issues or there is missing some kind of key salt. Btw when upgrading to newest version, can i somehow run the upgrade of db version on every blog to run in the background, or will et upgrade the first time the user logins to wp-admin ? as we have 10.000 blogs, it takes forever to wait for :-) –  Tonny Jørgensen Jan 24 '13 at 13:51
    
Once you upgrade to the latest version of WordPress, just go in to the Network Admin and go to the Update Network page (Network > Updates > Update Network). This should trigger the DB update on each site right away so that the users do not get prompted for the upgrade. Per the Update Network page: “You can update all the sites on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update.” –  Weston Ruter Jan 24 '13 at 17:35
    
i knowm but we have 12000 sites on this wpmu, so it takes alot of times, and the ajax refresh calls fails from time to time... it would be nice if there where somekind of cli script to take care of the update process. –  Tonny Jørgensen Feb 1 '13 at 12:44
    
If you have a list of the domains you can put them into a text file, say domains.txt and then do something like: for domain in $(cat domains.txt); do curl http://$domain/wp-admin/upgrade.php; done –  Weston Ruter Feb 1 '13 at 19:12
    
i have now tried this in my test setup and clearing of the memcache with flush_cache does not mess up the keys. Also there is now support for KEY_SALT prefix whick i have enabled :-) –  Tonny Jørgensen Feb 5 '13 at 14:07
add comment
up vote 0 down vote accepted

We upgraded to wordpress 3.5.1 and the latest version of object-cache.php this has now solved the problems.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.