* Introduced by r47317
*/
class BacklinkCache {
- /** @var ProcessCacheLRU */
- protected static $cache;
+ /** @var BacklinkCache */
+ protected static $instance;
/**
* Multi dimensions array representing batches. Keys are:
* @see BacklinkCache::partitionResult()
*
* Cleared with BacklinkCache::clear()
+ * @var array[]
*/
protected $partitionCache = array();
*
* Initialized with BacklinkCache::getLinks()
* Cleared with BacklinkCache::clear()
+ * @var ResultWrapper[]
*/
protected $fullResultCache = array();
* @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;
}
/**
* @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] );
$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 );
}
// 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 );
}
}
* @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" );
return $this->partitionCache[$table][$batchSize]['batches'];
}
+ $cache = ObjectCache::getMainWANInstance();
$this->partitionCache[$table][$batchSize] = false;
$cacheEntry =& $this->partitionCache[$table][$batchSize];
);
// 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" );
}
// 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" );