function load( $code = false ) {
global $wgUseLocalMessageCache;
+ $exception = null; // deferred error
+
if( !is_string( $code ) ) {
# This isn't really nice, so at least make a note about it and try to
# fall back
$where[] = 'loading from database';
$this->lock( $cacheKey );
-
# Limit the concurrency of loadFromDB to a single process
# This prevents the site from going down when the cache expires
$statusKey = wfMemcKey( 'messages', $code, 'status' );
$success = $this->mMemc->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT );
- if ( $success ) {
+ if ( $success ) { // acquired lock
$cache = $this->loadFromDB( $code );
$success = $this->setCache( $cache, $code );
- }
- if ( $success ) {
- $success = $this->saveToCaches( $cache, true, $code );
- if ( $success ) {
- $this->mMemc->delete( $statusKey );
+ if ( $success ) { // messages loaded
+ $success = $this->saveToCaches( $cache, true, $code );
+ if ( $success ) {
+ $this->mMemc->delete( $statusKey );
+ } else {
+ $this->mMemc->set( $statusKey, 'error', 60 * 5 );
+ wfDebug( __METHOD__ . ": set() error: restart memcached server!\n" );
+ $exception = new MWException( "Could not save cache for '$code'." );
+ }
} else {
- $this->mMemc->set( $statusKey, 'error', 60 * 5 );
- wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
+ $this->mMemc->delete( $statusKey );
+ $exception = new MWException( "Could not load cache from DB for '$code'." );
}
+ } else {
+ $exception = new MWException( "Could not acquire '$statusKey' lock." );
}
- $this->unlock($cacheKey);
+ $this->unlock( $cacheKey );
}
if ( !$success ) {
// This used to go on, but that led to lots of nasty side
// effects like gadgets and sidebar getting cached with their
// default content
- throw new MWException( "MessageCache failed to load messages" );
+ if ( $exception instanceof Exception ) {
+ throw $exception;
+ } else {
+ throw new MWException( "MessageCache failed to load messages" );
+ }
} else {
# All good, just record the success
$info = implode( ', ', $where );