* Article::viewRedirect() is deprecated.
* DeprecatedGlobal no longer supports passing in a direct value, it requires a
callable factory function or a class name.
+* The $parserMemc global, wfGetParserCacheStorage(), and ParserCache::singleton()
+ are all deprecated. The main ParserCache instance should be obtained from
+ MediaWikiServices instead. Access to the underlying BagOStuff is possible
+ through the new ParserCache::getCacheStorage() method.
== Compatibility ==
MediaWiki 1.30 requires PHP 5.5.9 or later. There is experimental support for
/**
* Get the cache object used by the parser cache
*
+ * @deprecated since 1.30, use MediaWikiServices::getParserCache()->getCacheStorage()
* @return BagOStuff
*/
function wfGetParserCacheStorage() {
use MimeAnalyzer;
use ObjectCache;
use Parser;
+use ParserCache;
use ProxyLookup;
use SearchEngine;
use SearchEngineConfig;
return $this->getService( 'Parser' );
}
+ /**
+ * @since 1.30
+ * @return ParserCache
+ */
+ public function getParserCache() {
+ return $this->getService( 'ParserCache' );
+ }
+
/**
* @since 1.28
* @return GenderCache
return ObjectFactory::constructClassInstance( $conf['class'], [ $conf ] );
},
- 'LinkCache' => function ( MediaWikiServices $services ) {
+ 'ParserCache' => function( MediaWikiServices $services ) {
+ $config = $services->getMainConfig();
+ $cache = ObjectCache::getInstance( $config->get( 'ParserCacheType' ) );
+ wfDebugLog( 'caches', 'parser: ' . get_class( $cache ) );
+
+ return new ParserCache(
+ $cache,
+ $config->get( 'CacheEpoch' )
+ );
+ },
+
+ 'LinkCache' => function( MediaWikiServices $services ) {
return new LinkCache(
$services->getTitleFormatter(),
$services->getMainWANObjectCache()
$wgMemc = wfGetMainCache();
$messageMemc = wfGetMessageCacheStorage();
-$parserMemc = wfGetParserCacheStorage();
+
+/**
+ * @deprecated since 1.30
+ */
+$parserMemc = new DeprecatedGlobal( 'parserMemc', function() {
+ return MediaWikiServices::getInstance()->getParserCache()->getCacheStorage();
+}, '1.30' );
wfDebugLog( 'caches',
'cluster: ' . get_class( $wgMemc ) .
', WAN: ' . ( $wgMainWANCache === CACHE_NONE ? 'CACHE_NONE' : $wgMainWANCache ) .
', stash: ' . $wgMainStash .
', message: ' . get_class( $messageMemc ) .
- ', parser: ' . get_class( $parserMemc ) .
', session: ' . get_class( ObjectCache::getInstance( $wgSessionCacheType ) )
);
* @ingroup Cache Parser
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @ingroup Cache Parser
* @todo document
/** @var BagOStuff */
private $mMemc;
+
+ /**
+ * Anything cached prior to this is invalidated
+ *
+ * @var string
+ */
+ private $cacheEpoch;
/**
* Get an instance of this object
*
+ * @deprecated since 1.30, use MediaWikiServices instead
* @return ParserCache
*/
public static function singleton() {
- static $instance;
- if ( !isset( $instance ) ) {
- global $parserMemc;
- $instance = new ParserCache( $parserMemc );
- }
- return $instance;
+ return MediaWikiServices::getInstance()->getParserCache();
}
/**
* This class use an invalidation strategy that is compatible with
* MultiWriteBagOStuff in async replication mode.
*
- * @param BagOStuff $memCached
+ * @param BagOStuff $cache
+ * @param string $cacheEpoch Anything before this timestamp is invalidated
* @throws MWException
*/
- protected function __construct( BagOStuff $memCached ) {
- $this->mMemc = $memCached;
+ public function __construct( BagOStuff $cache, $cacheEpoch = '20030516000000' ) {
+ $this->mMemc = $cache;
+ $this->cacheEpoch = $cacheEpoch;
}
/**
* @since 1.30 Changed $useOutdated to an int and added the non-boolean values
*/
public function getKey( $article, $popts, $useOutdated = self::USE_ANYTHING ) {
- global $wgCacheEpoch;
-
if ( is_bool( $useOutdated ) ) {
$useOutdated = $useOutdated ? self::USE_ANYTHING : self::USE_CURRENT_ONLY;
}
$cacheTime = $optionsKey->getCacheTime();
wfDebugLog( "ParserCache",
"Parser options key expired, touched " . $article->getTouched()
- . ", epoch $wgCacheEpoch, cached $cacheTime\n" );
+ . ", epoch {$this->cacheEpoch}, cached $cacheTime\n" );
return false;
} elseif ( $useOutdated < self::USE_OUTDATED &&
$optionsKey->isDifferentRevision( $article->getLatest() )
* @return ParserOutput|bool False on failure
*/
public function get( $article, $popts, $useOutdated = false ) {
- global $wgCacheEpoch;
-
$canCache = $article->checkTouched();
if ( !$canCache ) {
// It's a redirect now
$cacheTime = $value->getCacheTime();
wfDebugLog( "ParserCache",
"ParserOutput key expired, touched $touched, "
- . "epoch $wgCacheEpoch, cached $cacheTime\n" );
+ . "epoch {$this->cacheEpoch}, cached $cacheTime\n" );
$value = false;
} elseif ( !$useOutdated && $value->isDifferentRevision( $article->getLatest() ) ) {
wfIncrStats( "pcache.miss.revid" );
wfDebug( "Parser output was marked as uncacheable and has not been saved.\n" );
}
}
+
+ /**
+ * Get the backend BagOStuff instance that
+ * powers the parser cache
+ *
+ * @since 1.30
+ * @return BagOStuff
+ */
+ public function getCacheStorage() {
+ return $this->mMemc;
+ }
}
require __DIR__ . '/Maintenance.php';
+use MediaWiki\MediaWikiServices;
+
/**
* Maintenance script to remove old objects from the parser cache.
*
$this->output( "Deleting objects expiring before " .
$english->timeanddate( $date ) . "\n" );
- $pc = wfGetParserCacheStorage();
+ $pc = MediaWikiServices::getInstance()->getParserCache()->getCacheStorage();
$success = $pc->deleteObjectsExpiringBefore( $date, [ $this, 'showProgressAndWait' ] );
if ( !$success ) {
$this->error( "\nCannot purge this kind of parser cache.", 1 );
'CryptHKDF' => [ 'CryptHKDF', CryptHKDF::class ],
'MediaHandlerFactory' => [ 'MediaHandlerFactory', MediaHandlerFactory::class ],
'Parser' => [ 'Parser', Parser::class ],
+ 'ParserCache' => [ 'ParserCache', ParserCache::class ],
'GenderCache' => [ 'GenderCache', GenderCache::class ],
'LinkCache' => [ 'LinkCache', LinkCache::class ],
'LinkRenderer' => [ 'LinkRenderer', LinkRenderer::class ],
DeferredUpdates::clearPendingUpdates();
$wgMemc = wfGetMainCache();
$messageMemc = wfGetMessageCacheStorage();
- $parserMemc = wfGetParserCacheStorage();
RequestContext::resetMain();
$context = RequestContext::getMain();