Aaron Schulz has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/333323 )

Change subject: Inject remaining cache objects into MessageCache
......................................................................

Inject remaining cache objects into MessageCache

Change-Id: I431d6e9b443a00fdc1b65adb90ae9de496242f81
---
M includes/cache/MessageCache.php
1 file changed, 27 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/23/333323/1

diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index 352a94c..e12f6bc 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -89,10 +89,12 @@
         */
        protected $mInParser = false;
 
-       /** @var BagOStuff */
-       protected $mMemc;
        /** @var WANObjectCache */
        protected $wanCache;
+       /** @var BagOStuff */
+       protected $clusterCache;
+       /** @var BagOStuff */
+       protected $srvCache;
 
        /**
         * Singleton instance
@@ -109,9 +111,13 @@
         */
        public static function singleton() {
                if ( self::$instance === null ) {
-                       global $wgUseDatabaseMessages, $wgMsgCacheExpiry;
+                       global $wgUseDatabaseMessages, $wgMsgCacheExpiry, 
$wgUseLocalMessageCache;
                        self::$instance = new self(
+                               
MediaWikiServices::getInstance()->getMainWANObjectCache(),
                                wfGetMessageCacheStorage(),
+                               $wgUseLocalMessageCache
+                                       ? 
MediaWikiServices::getInstance()->getLocalServerObjectCache()
+                                       : new EmptyBagOStuff(),
                                $wgUseDatabaseMessages,
                                $wgMsgCacheExpiry
                        );
@@ -149,24 +155,21 @@
        }
 
        /**
-        * @param BagOStuff $memCached A cache instance. If none, fall back to 
CACHE_NONE.
-        * @param bool $useDB
+        * @param WANObjectCache $wanCache WAN cache instance
+        * @param BagOStuff $cCache Cluster cache instance
+        * @param BagOStuff $sCache Server cache instance
+        * @param bool $useDB Whether to look for message overrides (e.g. 
MediaWiki: pages)
         * @param int $expiry Lifetime for cache. @see $mExpiry.
         */
-       function __construct( BagOStuff $memCached, $useDB, $expiry ) {
-               global $wgUseLocalMessageCache;
+       public function __construct(
+               WANObjectCache $wanCache, BagOStuff $cCache, BagOStuff $sCache, 
$useDB, $expiry
+       ) {
+               $this->wanCache = $wanCache;
+               $this->clusterCache = $cCache;
+               $this->srvCache = $sCache;
 
-               $this->mMemc = $memCached;
                $this->mDisable = !$useDB;
                $this->mExpiry = $expiry;
-
-               if ( $wgUseLocalMessageCache ) {
-                       $this->localCache = 
MediaWikiServices::getInstance()->getLocalServerObjectCache();
-               } else {
-                       $this->localCache = new EmptyBagOStuff();
-               }
-
-               $this->wanCache = ObjectCache::getMainWANInstance();
        }
 
        /**
@@ -203,7 +206,7 @@
        protected function getLocalCache( $code ) {
                $cacheKey = wfMemcKey( __CLASS__, $code );
 
-               return $this->localCache->get( $cacheKey );
+               return $this->srvCache->get( $cacheKey );
        }
 
        /**
@@ -214,7 +217,7 @@
         */
        protected function saveToLocalCache( $code, $cache ) {
                $cacheKey = wfMemcKey( __CLASS__, $code );
-               $this->localCache->set( $cacheKey, $cache );
+               $this->srvCache->set( $cacheKey, $cache );
        }
 
        /**
@@ -300,7 +303,7 @@
                                        # below, and use the local stale value 
if it was not acquired.
                                        $where[] = 'global cache is presumed 
expired';
                                } else {
-                                       $cache = $this->mMemc->get( $cacheKey );
+                                       $cache = $this->clusterCache->get( 
$cacheKey );
                                        if ( !$cache ) {
                                                $where[] = 'global cache is 
empty';
                                        } elseif ( $this->isCacheExpired( 
$cache ) ) {
@@ -381,12 +384,10 @@
         * @return bool|string True on success or one of ("cantacquire", 
"disabled")
         */
        protected function loadFromDBWithLock( $code, array &$where, $mode = 
null ) {
-               global $wgUseLocalMessageCache;
-
                # If cache updates on all levels fail, give up on message 
overrides.
                # This is to avoid easy site outages; see $saveSuccess comments 
below.
                $statusKey = wfMemcKey( 'messages', $code, 'status' );
-               $status = $this->mMemc->get( $statusKey );
+               $status = $this->clusterCache->get( $statusKey );
                if ( $status === 'error' ) {
                        $where[] = "could not load; method is still globally 
disabled";
                        return 'disabled';
@@ -424,8 +425,8 @@
                         * 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 
);
+                       if ( $this->srvCache instanceof EmptyBagOStuff ) {
+                               $this->clusterCache->set( $statusKey, 'error', 
60 * 5 );
                                $where[] = 'could not save cache, disabled 
globally for 5 minutes';
                        } else {
                                $where[] = "could not save global cache";
@@ -648,7 +649,7 @@
        protected function saveToCaches( array $cache, $dest, $code = false ) {
                if ( $dest === 'all' ) {
                        $cacheKey = wfMemcKey( 'messages', $code );
-                       $success = $this->mMemc->set( $cacheKey, $cache );
+                       $success = $this->clusterCache->set( $cacheKey, $cache 
);
                        $this->setValidationHash( $code, $cache );
                } else {
                        $success = true;
@@ -720,7 +721,7 @@
         * @return null|ScopedCallback
         */
        protected function getReentrantScopedLock( $key, $timeout = 
self::WAIT_SEC ) {
-               return $this->mMemc->getScopedLock( $key, $timeout, 
self::LOCK_TTL, __METHOD__ );
+               return $this->clusterCache->getScopedLock( $key, $timeout, 
self::LOCK_TTL, __METHOD__ );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/333323
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I431d6e9b443a00fdc1b65adb90ae9de496242f81
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to