Make MessageCache use APC for big messages
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 25 Jun 2018 12:16:15 +0000 (13:16 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 25 Jul 2018 20:24:52 +0000 (13:24 -0700)
Bug: T118893
Change-Id: I418d0ca490911d7ee4213fe1728cfbc637ef8b10

includes/cache/MessageCache.php

index 48aac7e..7a172be 100644 (file)
@@ -1028,40 +1028,47 @@ class MessageCache {
         * @return string Either " <MESSAGE>" or "!NONEXISTANT"
         */
        private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
-               return $this->wanCache->getWithSetCallback(
-                       $this->bigMessageCacheKey( $hash, $dbKey ),
-                       $this->mExpiry,
-                       function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code ) {
-                               // Try loading the message from the database
-                               $dbr = wfGetDB( DB_REPLICA );
-                               $setOpts += Database::getCacheSetOptions( $dbr );
-                               // Use newKnownCurrent() to avoid querying revision/user tables
-                               $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey );
-                               $revision = Revision::newKnownCurrent( $dbr, $title );
-                               if ( !$revision ) {
-                                       // The wiki doesn't have a local override page. Cache absence with normal TTL.
-                                       // When overrides are created, self::replace() takes care of the cache.
-                                       return '!NONEXISTENT';
-                               }
-                               $content = $revision->getContent();
-                               if ( $content ) {
-                                       $message = $this->getMessageTextFromContent( $content );
-                               } else {
-                                       LoggerFactory::getInstance( 'MessageCache' )->warning(
-                                               __METHOD__ . ': failed to load page text for \'{titleKey}\'',
-                                               [ 'titleKey' => $dbKey, 'code' => $code ]
-                                       );
-                                       $message = null;
-                               }
-
-                               if ( !is_string( $message ) ) {
-                                       // Revision failed to load Content, or Content is incompatible with wikitext.
-                                       // Possibly a temporary loading failure.
-                                       $ttl = 5;
-                                       return '!NONEXISTENT';
-                               }
-
-                               return ' ' . $message;
+               return $this->srvCache->getWithSetCallback(
+                       $this->srvCache->makeKey( 'messages-big', $hash, $dbKey ),
+                       IExpiringStore::TTL_MINUTE,
+                       function () use ( $code, $dbKey, $hash ) {
+                               return $this->wanCache->getWithSetCallback(
+                                       $this->bigMessageCacheKey( $hash, $dbKey ),
+                                       $this->mExpiry,
+                                       function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code ) {
+                                               // Try loading the message from the database
+                                               $dbr = wfGetDB( DB_REPLICA );
+                                               $setOpts += Database::getCacheSetOptions( $dbr );
+                                               // Use newKnownCurrent() to avoid querying revision/user tables
+                                               $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey );
+                                               $revision = Revision::newKnownCurrent( $dbr, $title );
+                                               if ( !$revision ) {
+                                                       // The wiki doesn't have a local override page. Cache absence with normal TTL.
+                                                       // When overrides are created, self::replace() takes care of the cache.
+                                                       return '!NONEXISTENT';
+                                               }
+                                               $content = $revision->getContent();
+                                               if ( $content ) {
+                                                       $message = $this->getMessageTextFromContent( $content );
+                                               } else {
+                                                       LoggerFactory::getInstance( 'MessageCache' )->warning(
+                                                               __METHOD__ . ': failed to load page text for \'{titleKey}\'',
+                                                               [ 'titleKey' => $dbKey, 'code' => $code ]
+                                                       );
+                                                       $message = null;
+                                               }
+
+                                               if ( !is_string( $message ) ) {
+                                                       // Revision failed to load Content, or Content is incompatible with wikitext.
+                                                       // Possibly a temporary loading failure.
+                                                       $ttl = 5;
+
+                                                       return '!NONEXISTENT';
+                                               }
+
+                                               return ' ' . $message;
+                                       }
+                               );
                        }
                );
        }