* it will be generated with the callback function (if present), and the newly
* calculated value will be stored to the cache in a wrapper.
*
- * @param BagOStuff $cache A cache object such as $wgMemc
+ * @param BagOStuff $cache A cache object
* @param string $key The cache key
* @param int $expiry The expiry timestamp or interval in seconds
* @param bool|callable $callback The callback for generating the value, or false
* @param int $delta Delta (positive or negative)
*/
protected function adjustPending( $type, $delta ) {
- global $wgMemc;
-
+ $cache = ObjectCache::getMainStashInstance();
if ( $delta < 0 ) { // decrement
$key = $this->getTypeCacheKey( $type, '-' );
} else { // increment
}
$magnitude = abs( $delta );
- if ( !$wgMemc->incr( $key, $magnitude ) ) { // not there?
- if ( !$wgMemc->add( $key, $magnitude ) ) { // race?
- $wgMemc->incr( $key, $magnitude );
- }
- }
+ $cache->incrWithInit( $key, 0, $magnitude, $magnitude );
}
/**
* @return array Positive and negative deltas for each type
*/
protected function getPendingDeltas() {
- global $wgMemc;
+ $cache = ObjectCache::getMainStashInstance();
$pending = array();
foreach ( array( 'ss_total_edits',
'ss_good_articles', 'ss_total_pages', 'ss_users', 'ss_images' ) as $type
) {
// Get pending increments and pending decrements
- $pending[$type]['+'] = (int)$wgMemc->get( $this->getTypeCacheKey( $type, '+' ) );
- $pending[$type]['-'] = (int)$wgMemc->get( $this->getTypeCacheKey( $type, '-' ) );
+ $flg = BagOStuff::READ_LATEST;
+ $pending[$type]['+'] = (int)$cache->get( $this->getTypeCacheKey( $type, '+' ), $flg );
+ $pending[$type]['-'] = (int)$cache->get( $this->getTypeCacheKey( $type, '-' ), $flg );
}
return $pending;
* @param array $pd Result of getPendingDeltas(), used for DB update
*/
protected function removePendingDeltas( array $pd ) {
- global $wgMemc;
+ $cache = ObjectCache::getMainStashInstance();
foreach ( $pd as $type => $deltas ) {
foreach ( $deltas as $sign => $magnitude ) {
// Lower the pending counter now that we applied these changes
- $wgMemc->decr( $this->getTypeCacheKey( $type, $sign ), $magnitude );
+ $cache->decr( $this->getTypeCacheKey( $type, $sign ), $magnitude );
}
}
}
* Purpose: Memory storage for per-cluster coordination and tracking.
* A typical use case would be a rate limit counter or cache regeneration mutex.
* Stored centrally within the local data-center. Not replicated to other DCs.
- * Also known as $wgMemc. Configured by $wgMainCacheType.
+ * Configured by $wgMainCacheType.
*
* - wfGetCache( $cacheType )
* Get a specific cache type by key in $wgObjectCaches.
// It's necessary to register a shutdown function to call session_write_close(),
// because by the time the request shutdown function for the session module is
- // called, $wgMemc has already been destroyed. Shutdown functions registered
+ // called, the BagOStuff has already been destroyed. Shutdown functions registered
// this way are called before object destruction.
register_shutdown_function( array( __CLASS__, 'handleShutdown' ) );
}