Merge "[search] Fix method call on null value"
[lhc/web/wiklou.git] / includes / cache / MessageCache.php
index 9a6f7d0..bcfa792 100644 (file)
@@ -394,21 +394,19 @@ class MessageCache {
                $saveSuccess = $this->saveToCaches( $cache, 'all', $code );
 
                if ( !$saveSuccess ) {
-                       # Cache save has failed.
-                       # There are two main scenarios where this could be a problem:
-                       #
-                       #   - The cache is more than the maximum size (typically
-                       #     1MB compressed).
-                       #
-                       #   - Memcached has no space remaining in the relevant slab
-                       #     class. This is unlikely with recent versions of
-                       #     memcached.
-                       #
-                       # Either way, if there is a local cache, nothing bad will
-                       # happen. If there is no local cache, disabling the message
-                       # cache for all requests avoids incurring a loadFromDB()
-                       # overhead on every request, and thus saves the wiki from
-                       # complete downtime under moderate traffic conditions.
+                       /**
+                        * Cache save has failed.
+                        *
+                        * There are two main scenarios where this could be a problem:
+                        * - The cache is more than the maximum size (typically 1MB compressed).
+                        * - Memcached has no space remaining in the relevant slab class. This is
+                        *   unlikely with recent versions of memcached.
+                        *
+                        * Either way, if there is a local cache, nothing bad will happen. If there
+                        * is no local cache, disabling the message cache for all requests avoids
+                        * incurring a loadFromDB() overhead on every request, and thus saves the
+                        * wiki from complete downtime under moderate traffic conditions.
+                        */
                        if ( !$wgUseLocalMessageCache ) {
                                $this->mMemc->set( $statusKey, 'error', 60 * 5 );
                                $where[] = 'could not save cache, disabled globally for 5 minutes';
@@ -576,7 +574,7 @@ class MessageCache {
 
                foreach ( $codes as $code ) {
                        $sidebarKey = wfMemcKey( 'sidebar', $code );
-                       $this->wanCache->delete( $sidebarKey, 5 );
+                       $this->wanCache->delete( $sidebarKey );
                }
 
                // Update the message in the message blob store
@@ -645,16 +643,20 @@ class MessageCache {
 
                if ( !$value ) {
                        // No hash found at all; cache must regenerate to be safe
+                       $hash = false;
                        $expired = true;
-               } elseif ( ( time() - $value['latest'] ) < WANObjectCache::HOLDOFF_TTL ) {
-                       // Cache was recently updated via replace() and should be up-to-date
-                       $expired = false;
                } else {
-                       // See if the "check" key was bumped after the hash was generated
-                       $expired = ( $curTTL < 0 );
+                       $hash = $value['hash'];
+                       if ( ( time() - $value['latest'] ) < WANObjectCache::HOLDOFF_TTL ) {
+                               // Cache was recently updated via replace() and should be up-to-date
+                               $expired = false;
+                       } else {
+                               // See if the "check" key was bumped after the hash was generated
+                               $expired = ( $curTTL < 0 );
+                       }
                }
 
-               return array( $value['hash'], $expired );
+               return array( $hash, $expired );
        }
 
        /**
@@ -673,7 +675,7 @@ class MessageCache {
                                'hash' => $cache['HASH'],
                                'latest' => isset( $cache['LATEST'] ) ? $cache['LATEST'] : 0
                        ),
-                       WANObjectCache::TTL_NONE
+                       WANObjectCache::TTL_INDEFINITE
                );
        }