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;
157 $contentModel = str_replace(
'.',
'_', $article->getContentModel() );
158 $metricSuffix = str_replace(
'.',
'_', $metricSuffix );
159 wfIncrStats(
'pcache.' . $contentModel .
'.' . $metricSuffix );
182 public function getKey( $article, $popts, $useOutdated = self::USE_ANYTHING ) {
183 if ( is_bool( $useOutdated ) ) {
187 if ( $popts instanceof
User ) {
188 wfWarn(
"Use of outdated prototype ParserCache::getKey( &\$article, &\$user )\n" );
193 $optionsKey = $this->cache->get(
195 if ( $optionsKey instanceof
CacheTime ) {
196 if ( $useOutdated < self::USE_EXPIRED && $optionsKey->expired( $article->getTouched() ) ) {
198 $cacheTime = $optionsKey->getCacheTime();
200 "Parser options key expired, touched " . $article->getTouched()
201 .
", epoch {$this->cacheEpoch}, cached $cacheTime\n" );
203 } elseif ( $useOutdated < self::USE_OUTDATED &&
204 $optionsKey->isDifferentRevision( $article->getLatest() )
207 $revId = $article->getLatest();
208 $cachedRevId = $optionsKey->getCacheRevisionId();
210 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
216 $usedOptions = $optionsKey->mUsedOptions;
217 wfDebug(
"Parser cache options found.\n" );
219 if ( $useOutdated < self::USE_ANYTHING ) {
227 $popts->optionsHash( $usedOptions, $article->getTitle() )
241 public function get( $article, $popts, $useOutdated = false ) {
242 $canCache = $article->checkTouched();
248 $touched = $article->getTouched();
250 $parserOutputKey = $this->
getKey( $article, $popts,
251 $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
253 if ( $parserOutputKey ===
false ) {
262 wfDebug(
"ParserOutput cache miss.\n" );
267 wfDebug(
"ParserOutput cache found.\n" );
269 $wikiPage = method_exists( $article,
'getPage' )
270 ? $article->getPage()
273 if ( !$useOutdated && $value->expired( $touched ) ) {
275 $cacheTime = $value->getCacheTime();
277 "ParserOutput key expired, touched $touched, "
278 .
"epoch {$this->cacheEpoch}, cached $cacheTime\n" );
280 } elseif ( !$useOutdated && $value->isDifferentRevision( $article->getLatest() ) ) {
282 $revId = $article->getLatest();
283 $cachedRevId = $value->getCacheRevisionId();
285 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
289 Hooks::run(
'RejectParserCacheValue', [ $value, $wikiPage, $popts ] ) ===
false
293 "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"
317 if ( !$parserOutput->
hasText() ) {
318 throw new InvalidArgumentException(
'Attempt to cache a ParserOutput with no text set!' );
325 $revision = $page->getRevision();
326 $revId = $revision ? $revision->getId() :
null;
331 $optionsKey->updateCacheExpiry( $expire );
333 $optionsKey->setCacheTime( $cacheTime );
335 $optionsKey->setCacheRevisionId( $revId );
339 $popts->optionsHash( $optionsKey->mUsedOptions, $page->getTitle() ) );
344 $msg =
"Saved in parser cache with key $parserOutputKey" .
345 " and timestamp $cacheTime" .
346 " and revision id $revId" .
349 $parserOutput->mText .=
"\n<!-- $msg -->\n";
361 $this->cache->set( $this->
getOptionsKey( $page ), $optionsKey, $expire );
364 'ParserCacheSaveComplete',
365 [ $this, $parserOutput, $page->getTitle(), $popts, $revId ]
367 } elseif ( $expire <= 0 ) {
368 wfDebug(
"Parser output was marked as uncacheable and has not been saved.\n" );