77 return MediaWikiServices::getInstance()->getParserCache();
94 $cacheEpoch =
'20030516000000',
101 $hookContainer ?: MediaWikiServices::getInstance()->getHookContainer()
103 $this->stats =
$stats ?: MediaWikiServices::getInstance()->getStatsdDataFactory();
115 $pageid = $wikiPage->
getId();
116 $renderkey = (int)(
$wgRequest->getVal(
'action' ) ==
'render' );
118 $key = $this->cache->makeKey(
'pcache',
'idhash',
"{$pageid}-{$renderkey}!{$hash}" );
127 return $this->cache->makeKey(
'pcache',
'idoptions', $wikiPage->
getId() );
157 ParserOptions::allCacheVaryingOptions(),
171 $value = $this->
get( $wikiPage, $popts,
true );
172 return is_object( $value ) ? $value :
false;
181 $metricSuffix = str_replace(
'.',
'_', $metricSuffix );
182 $this->stats->increment(
'pcache.' . $contentModel .
'.' . $metricSuffix );
205 public function getKey(
WikiPage $wikiPage, $popts, $useOutdated = self::USE_ANYTHING ) {
206 if ( is_bool( $useOutdated ) ) {
207 $useOutdated = $useOutdated ? self::USE_ANYTHING : self::USE_CURRENT_ONLY;
210 if ( $popts instanceof
User ) {
211 wfWarn(
"Use of outdated prototype ParserCache::getKey( &\$wikiPage, &\$user )\n" );
212 $popts = ParserOptions::newFromUser( $popts );
216 $optionsKey = $this->cache->get(
217 $this->
getOptionsKey( $wikiPage ), BagOStuff::READ_VERIFIED );
218 if ( $optionsKey instanceof
CacheTime ) {
220 $useOutdated < self::USE_EXPIRED
221 && $optionsKey->expired( $wikiPage->
getTouched() )
224 $cacheTime = $optionsKey->getCacheTime();
226 "Parser options key expired, touched {$wikiPage->getTouched()}"
227 .
", epoch {$this->cacheEpoch}, cached $cacheTime" );
229 } elseif ( $useOutdated < self::USE_OUTDATED &&
230 $optionsKey->isDifferentRevision( $wikiPage->
getLatest() )
234 $cachedRevId = $optionsKey->getCacheRevisionId();
236 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId"
242 $usedOptions = $optionsKey->mUsedOptions;
243 wfDebug(
"Parser cache options found." );
245 if ( $useOutdated < self::USE_ANYTHING ) {
248 $usedOptions = ParserOptions::allCacheVaryingOptions();
253 $popts->optionsHash( $usedOptions, $wikiPage->
getTitle() )
267 public function get(
Page $wikiPage, $popts, $useOutdated = false ) {
268 if ( $wikiPage instanceof
Article ) {
270 __METHOD__ .
' with Article parameter',
273 $wikiPage = $wikiPage->getPage();
276 $canCache = $wikiPage->checkTouched();
282 $touched = $wikiPage->getTouched();
284 $parserOutputKey = $this->
getKey( $wikiPage, $popts,
285 $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
287 if ( $parserOutputKey ===
false ) {
294 $value = $this->cache->get( $parserOutputKey, BagOStuff::READ_VERIFIED );
296 wfDebug(
"ParserOutput cache miss." );
301 wfDebug(
"ParserOutput cache found." );
303 if ( !$useOutdated && $value->expired( $touched ) ) {
305 $cacheTime = $value->getCacheTime();
307 "ParserOutput key expired, touched $touched, "
308 .
"epoch {$this->cacheEpoch}, cached $cacheTime" );
312 && $value->isDifferentRevision( $wikiPage->getLatest() )
315 $revId = $wikiPage->getLatest();
316 $cachedRevId = $value->getCacheRevisionId();
318 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId"
322 $this->hookRunner->onRejectParserCacheValue( $value, $wikiPage, $popts ) ===
false
326 "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler."
350 if ( !$parserOutput->
hasText() ) {
351 throw new InvalidArgumentException(
'Attempt to cache a ParserOutput with no text set!' );
359 $revId = $revision ? $revision->getId() :
null;
364 $optionsKey->updateCacheExpiry( $expire );
366 $optionsKey->setCacheTime( $cacheTime );
368 $optionsKey->setCacheRevisionId( $revId );
372 $popts->optionsHash( $optionsKey->mUsedOptions, $wikiPage->
getTitle() ) );
377 $msg =
"Saved in parser cache with key $parserOutputKey" .
378 " and timestamp $cacheTime" .
379 " and revision id $revId";
381 $parserOutput->mText .=
"\n<!-- $msg\n -->\n";
389 BagOStuff::WRITE_ALLOW_SEGMENTS
393 $this->cache->set( $this->
getOptionsKey( $wikiPage ), $optionsKey, $expire );
395 $this->hookRunner->onParserCacheSaveComplete(
396 $this, $parserOutput, $wikiPage->
getTitle(), $popts, $revId );
397 } elseif ( $expire <= 0 ) {
398 wfDebug(
"Parser output was marked as uncacheable and has not been saved." );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
if(! $wgDBerrorLogTZ) $wgRequest
Class for viewing MediaWiki article and history.
Class representing a cache/ephemeral data store.
Parser cache specific expiry check.
setCacheTime( $t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
getCacheExpiry()
Returns the number of seconds after which this object should expire.
A BagOStuff object with no objects in it.
const USE_EXPIRED
Use expired data if current data is unavailable.
getETag(WikiPage $wikiPage, $popts)
Provides an E-Tag suitable for the whole page.
static singleton()
Get an instance of this object.
getCacheStorage()
Get the backend BagOStuff instance that powers the parser cache.
getOptionsKey(WikiPage $wikiPage)
const USE_ANYTHING
Use expired data and data from different revisions, and if all else fails vary on all variable option...
save(ParserOutput $parserOutput, WikiPage $wikiPage, $popts, $cacheTime=null, $revId=null)
getParserOutputKey(WikiPage $wikiPage, $hash)
string $cacheEpoch
Anything cached prior to this is invalidated.
const USE_CURRENT_ONLY
Constants for self::getKey()
incrementStats(WikiPage $wikiPage, $metricSuffix)
IBufferingStatsdDataFactory $stats
const USE_OUTDATED
Use expired data or data from different revisions if current data is unavailable.
getKey(WikiPage $wikiPage, $popts, $useOutdated=self::USE_ANYTHING)
Generates a key for caching the given page considering the given parser options.
getDirty(WikiPage $wikiPage, $popts)
Retrieve the ParserOutput from ParserCache, even if it's outdated.
__construct(BagOStuff $cache, $cacheEpoch='20030516000000', HookContainer $hookContainer=null, IBufferingStatsdDataFactory $stats=null)
Setup a cache pathway with a given back-end storage mechanism.
deleteOptionsKey(WikiPage $wikiPage)
hasText()
Returns true if text was passed to the constructor, or set using setText().
getUsedOptions()
Returns the options from its ParserOptions which have been taken into account to produce this output.
setTimestamp( $timestamp)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
getLatest()
Get the page_latest field.
getContentModel()
Returns the page's content model id (see the CONTENT_MODEL_XXX constants).
getTitle()
Get the title object of the article.
getRevisionRecord()
Get the latest revision.
getTouched()
Get the page_touched field.
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)