/**
* Set the Database object to use
*
- * @param DatabaseBase $db
+ * @param IDatabase $db
*/
public function setDB( $db ) {
$this->db = $db;
* @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" );