68 return MediaWikiServices::getInstance()->getParserCache();
95 $pageid = $article->getId();
96 $renderkey = (int)(
$wgRequest->getVal(
'action' ) ==
'render' );
98 $key = $this->cache->makeKey(
'pcache',
'idhash',
"{$pageid}-{$renderkey}!{$hash}" );
107 return $this->cache->makeKey(
'pcache',
'idoptions', $page->getId() );
135 "--" . $article->getTouched() .
'"';
145 $value = $this->
get( $article, $popts,
true );
146 return is_object( $value ) ? $value :
false;
154 $contentModel = str_replace(
'.',
'_', $article->getContentModel() );
155 $metricSuffix = str_replace(
'.',
'_', $metricSuffix );
156 wfIncrStats(
'pcache.' . $contentModel .
'.' . $metricSuffix );
179 public function getKey( $article, $popts, $useOutdated = self::USE_ANYTHING ) {
180 if ( is_bool( $useOutdated ) ) {
184 if ( $popts instanceof
User ) {
185 wfWarn(
"Use of outdated prototype ParserCache::getKey( &\$article, &\$user )\n" );
190 $optionsKey = $this->cache->get(
192 if ( $optionsKey instanceof
CacheTime ) {
193 if ( $useOutdated < self::USE_EXPIRED && $optionsKey->expired( $article->getTouched() ) ) {
195 $cacheTime = $optionsKey->getCacheTime();
197 "Parser options key expired, touched " . $article->getTouched()
198 .
", epoch {$this->cacheEpoch}, cached $cacheTime\n" );
200 } elseif ( $useOutdated < self::USE_OUTDATED &&
201 $optionsKey->isDifferentRevision( $article->getLatest() )
204 $revId = $article->getLatest();
205 $cachedRevId = $optionsKey->getCacheRevisionId();
207 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
213 $usedOptions = $optionsKey->mUsedOptions;
214 wfDebug(
"Parser cache options found.\n" );
216 if ( $useOutdated < self::USE_ANYTHING ) {
224 $popts->optionsHash( $usedOptions, $article->getTitle() )
238 public function get( $article, $popts, $useOutdated = false ) {
239 $canCache = $article->checkTouched();
245 $touched = $article->getTouched();
247 $parserOutputKey = $this->
getKey( $article, $popts,
248 $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
250 if ( $parserOutputKey ===
false ) {
259 wfDebug(
"ParserOutput cache miss.\n" );
264 wfDebug(
"ParserOutput cache found.\n" );
266 $wikiPage = method_exists( $article,
'getPage' )
267 ? $article->getPage()
270 if ( !$useOutdated && $value->expired( $touched ) ) {
272 $cacheTime = $value->getCacheTime();
274 "ParserOutput key expired, touched $touched, "
275 .
"epoch {$this->cacheEpoch}, cached $cacheTime\n" );
277 } elseif ( !$useOutdated && $value->isDifferentRevision( $article->getLatest() ) ) {
279 $revId = $article->getLatest();
280 $cachedRevId = $value->getCacheRevisionId();
282 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
286 Hooks::run(
'RejectParserCacheValue', [ $value, $wikiPage, $popts ] ) ===
false
290 "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"
314 if ( !$parserOutput->
hasText() ) {
315 throw new InvalidArgumentException(
'Attempt to cache a ParserOutput with no text set!' );
322 $revision = $page->getRevision();
323 $revId = $revision ? $revision->getId() :
null;
328 $optionsKey->updateCacheExpiry( $expire );
330 $optionsKey->setCacheTime( $cacheTime );
332 $optionsKey->setCacheRevisionId( $revId );
336 $popts->optionsHash( $optionsKey->mUsedOptions, $page->getTitle() ) );
341 $msg =
"Saved in parser cache with key $parserOutputKey" .
342 " and timestamp $cacheTime" .
343 " and revision id $revId" .
346 $parserOutput->mText .=
"\n<!-- $msg -->\n";
358 $this->cache->set( $this->
getOptionsKey( $page ), $optionsKey, $expire );
361 'ParserCacheSaveComplete',
362 [ $this, $parserOutput, $page->getTitle(), $popts, $revId ]
364 } elseif ( $expire <= 0 ) {
365 wfDebug(
"Parser output was marked as uncacheable and has not been saved.\n" );