- $wgMemc->set( $this->mMemcKey, "loading", MSG_LOAD_TIMEOUT );
- $this->loadFromDB();
- # Save in memcached
- if ( !$wgMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry ) ) {
- # Hack for slabs reassignment problem
- $wgMemc->set( $this->mMemcKey, "error" );
- wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
+ $success = $this->mMemc->add( $this->mMemcKey, "loading", MSG_LOAD_TIMEOUT );
+ if ( $success ) {
+ wfProfileIn( $fname.'-load' );
+ $this->loadFromDB();
+ wfProfileOut( $fname.'-load' );
+ # Save in memcached
+ # Keep trying if it fails, this is kind of important
+ wfProfileIn( $fname.'-save' );
+ for ( $i=0; $i<20 && !$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry ); $i++ ) {
+ usleep(mt_rand(500000,1500000));
+ }
+ wfProfileOut( $fname.'-save' );
+ if ( $i == 20 ) {
+ $this->mMemc->set( $this->mMemcKey, 'error', 60*5 );
+ wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
+ }