*/
protected $mInParser = false;
- /** @var BagOStuff */
- protected $mMemc;
/** @var WANObjectCache */
protected $wanCache;
+ /** @var BagOStuff */
+ protected $clusterCache;
+ /** @var BagOStuff */
+ protected $srvCache;
/**
* Singleton instance
*/
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
);
}
/**
- * @param BagOStuff $memCached A cache instance. If none, fall back to CACHE_NONE.
- * @param bool $useDB
+ * @param WANObjectCache $wanCache WAN cache instance
+ * @param BagOStuff $clusterCache Cluster cache instance
+ * @param BagOStuff $srvCache 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 $clusterCache,
+ BagOStuff $srvCache,
+ $useDB,
+ $expiry
+ ) {
+ $this->wanCache = $wanCache;
+ $this->clusterCache = $clusterCache;
+ $this->srvCache = $srvCache;
- $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();
}
/**
protected function getLocalCache( $code ) {
$cacheKey = wfMemcKey( __CLASS__, $code );
- return $this->localCache->get( $cacheKey );
+ return $this->srvCache->get( $cacheKey );
}
/**
*/
protected function saveToLocalCache( $code, $cache ) {
$cacheKey = wfMemcKey( __CLASS__, $code );
- $this->localCache->set( $cacheKey, $cache );
+ $this->srvCache->set( $cacheKey, $cache );
}
/**
# 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 ) ) {
* @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';
* 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";
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;
* @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__ );
}
/**