Merge "Show change tags on Special:RevisionDelete"
[lhc/web/wiklou.git] / includes / cache / BacklinkCache.php
index 1296c13..c04a22a 100644 (file)
@@ -40,8 +40,8 @@
  * Introduced by r47317
  */
 class BacklinkCache {
-       /** @var ProcessCacheLRU */
-       protected static $cache;
+       /** @var BacklinkCache */
+       protected static $instance;
 
        /**
         * Multi dimensions array representing batches. Keys are:
@@ -53,6 +53,7 @@ class BacklinkCache {
         * @see BacklinkCache::partitionResult()
         *
         * Cleared with BacklinkCache::clear()
+        * @var array[]
         */
        protected $partitionCache = array();
 
@@ -62,6 +63,7 @@ class BacklinkCache {
         *
         * Initialized with BacklinkCache::getLinks()
         * Cleared with BacklinkCache::clear()
+        * @var ResultWrapper[]
         */
        protected $fullResultCache = array();
 
@@ -99,15 +101,10 @@ class BacklinkCache {
         * @return BacklinkCache
         */
        public static function get( Title $title ) {
-               if ( !self::$cache ) { // init cache
-                       self::$cache = new ProcessCacheLRU( 1 );
+               if ( !self::$instance || !self::$instance->title->equals( $title ) ) {
+                       self::$instance = new self( $title );
                }
-               $dbKey = $title->getPrefixedDBkey();
-               if ( !self::$cache->has( $dbKey, 'obj', 3600 ) ) {
-                       self::$cache->set( $dbKey, 'obj', new self( $title ) );
-               }
-
-               return self::$cache->get( $dbKey, 'obj' );
+               return self::$instance;
        }
 
        /**
@@ -133,7 +130,7 @@ class BacklinkCache {
        /**
         * Set the Database object to use
         *
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         */
        public function setDB( $db ) {
                $this->db = $db;
@@ -323,8 +320,9 @@ class BacklinkCache {
         * @return int
         */
        public function getNumLinks( $table, $max = INF ) {
-               global $wgMemc, $wgUpdateRowsPerJob;
+               global $wgUpdateRowsPerJob;
 
+               $cache = ObjectCache::getMainWANInstance();
                // 1) try partition cache ...
                if ( isset( $this->partitionCache[$table] ) ) {
                        $entry = reset( $this->partitionCache[$table] );
@@ -340,7 +338,7 @@ class BacklinkCache {
                $memcKey = wfMemcKey( 'numbacklinks', md5( $this->title->getPrefixedDBkey() ), $table );
 
                // 3) ... fallback to memcached ...
-               $count = $wgMemc->get( $memcKey );
+               $count = $cache->get( $memcKey );
                if ( $count ) {
                        return min( $max, $count );
                }
@@ -355,7 +353,7 @@ class BacklinkCache {
                        // Fetch the full title info, since the caller will likely need it next
                        $count = $this->getLinks( $table, false, false, $max )->count();
                        if ( $count < $max ) { // full count
-                               $wgMemc->set( $memcKey, $count, self::CACHE_EXPIRY );
+                               $cache->set( $memcKey, $count, self::CACHE_EXPIRY );
                        }
                }
 
@@ -372,8 +370,6 @@ class BacklinkCache {
         * @return array
         */
        public function partition( $table, $batchSize ) {
-               global $wgMemc;
-
                // 1) try partition cache ...
                if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
                        wfDebug( __METHOD__ . ": got from partition cache\n" );
@@ -381,6 +377,7 @@ class BacklinkCache {
                        return $this->partitionCache[$table][$batchSize]['batches'];
                }
 
+               $cache = ObjectCache::getMainWANInstance();
                $this->partitionCache[$table][$batchSize] = false;
                $cacheEntry =& $this->partitionCache[$table][$batchSize];
 
@@ -400,7 +397,7 @@ class BacklinkCache {
                );
 
                // 3) ... fallback to memcached ...
-               $memcValue = $wgMemc->get( $memcKey );
+               $memcValue = $cache->get( $memcKey );
                if ( is_array( $memcValue ) ) {
                        $cacheEntry = $memcValue;
                        wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
@@ -432,11 +429,11 @@ class BacklinkCache {
                }
 
                // Save partitions to memcached
-               $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
+               $cache->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
 
                // Save backlink count to memcached
                $memcKey = wfMemcKey( 'numbacklinks', md5( $this->title->getPrefixedDBkey() ), $table );
-               $wgMemc->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
+               $cache->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
 
                wfDebug( __METHOD__ . ": got from database\n" );