67 return MediaWikiServices::getInstance()->getParserCache();
94 $pageid = $article->getId();
95 $renderkey = (int)(
$wgRequest->getVal(
'action' ) ==
'render' );
97 $key = $this->mMemc->makeKey(
'pcache',
'idhash',
"{$pageid}-{$renderkey}!{$hash}" );
106 return $this->mMemc->makeKey(
'pcache',
'idoptions', $page->getId() );
133 $popts->optionsHash( ParserOptions::allCacheVaryingOptions(), $article->getTitle() ) ) .
134 "--" . $article->getTouched() .
'"';
168 public function getKey( $article, $popts, $useOutdated = self::USE_ANYTHING ) {
169 if ( is_bool( $useOutdated ) ) {
170 $useOutdated = $useOutdated ? self::USE_ANYTHING : self::USE_CURRENT_ONLY;
173 if ( $popts instanceof
User ) {
174 wfWarn(
"Use of outdated prototype ParserCache::getKey( &\$article, &\$user )\n" );
175 $popts = ParserOptions::newFromUser( $popts );
180 $optionsKey = $this->mMemc->get(
181 $this->
getOptionsKey( $article ), $casToken, BagOStuff::READ_VERIFIED );
182 if ( $optionsKey instanceof
CacheTime ) {
183 if ( $useOutdated < self::USE_EXPIRED && $optionsKey->expired( $article->getTouched() ) ) {
185 $cacheTime = $optionsKey->getCacheTime();
187 "Parser options key expired, touched " . $article->getTouched()
188 .
", epoch {$this->cacheEpoch}, cached $cacheTime\n" );
190 } elseif ( $useOutdated < self::USE_OUTDATED &&
191 $optionsKey->isDifferentRevision( $article->getLatest() )
194 $revId = $article->getLatest();
195 $cachedRevId = $optionsKey->getCacheRevisionId();
197 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
203 $usedOptions = $optionsKey->mUsedOptions;
204 wfDebug(
"Parser cache options found.\n" );
206 if ( $useOutdated < self::USE_ANYTHING ) {
209 $usedOptions = ParserOptions::allCacheVaryingOptions();
214 $popts->optionsHash( $usedOptions, $article->getTitle() )
229 $canCache = $article->checkTouched();
235 $touched = $article->getTouched();
237 $parserOutputKey = $this->
getKey( $article, $popts,
238 $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
240 if ( $parserOutputKey ===
false ) {
247 $value = $this->mMemc->get( $parserOutputKey, $casToken, BagOStuff::READ_VERIFIED );
249 wfDebug(
"ParserOutput cache miss.\n" );
254 wfDebug(
"ParserOutput cache found.\n" );
256 $wikiPage = method_exists( $article,
'getPage' )
257 ? $article->getPage()
260 if ( !$useOutdated &&
$value->expired( $touched ) ) {
262 $cacheTime =
$value->getCacheTime();
264 "ParserOutput key expired, touched $touched, "
265 .
"epoch {$this->cacheEpoch}, cached $cacheTime\n" );
267 } elseif ( !$useOutdated &&
$value->isDifferentRevision( $article->getLatest() ) ) {
269 $revId = $article->getLatest();
270 $cachedRevId =
$value->getCacheRevisionId();
272 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
276 Hooks::run(
'RejectParserCacheValue', [
$value, $wikiPage, $popts ] ) ===
false
280 "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"
297 public function save( $parserOutput, $page, $popts, $cacheTime =
null, $revId =
null ) {
298 $expire = $parserOutput->getCacheExpiry();
302 $revision = $page->getRevision();
303 $revId = $revision ? $revision->getId() :
null;
307 $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
310 $optionsKey->setCacheTime( $cacheTime );
311 $parserOutput->setCacheTime( $cacheTime );
312 $optionsKey->setCacheRevisionId( $revId );
313 $parserOutput->setCacheRevisionId( $revId );
316 $popts->optionsHash( $optionsKey->mUsedOptions, $page->getTitle() ) );
319 $parserOutput->setTimestamp( $page->getTimestamp() );
321 $msg =
"Saved in parser cache with key $parserOutputKey" .
322 " and timestamp $cacheTime" .
323 " and revision id $revId" .
326 $parserOutput->mText .=
"\n<!-- $msg -->\n";
330 $this->mMemc->set( $parserOutputKey, $parserOutput, $expire );
333 $this->mMemc->set( $this->
getOptionsKey( $page ), $optionsKey, $expire );
336 'ParserCacheSaveComplete',
337 [ $this, $parserOutput, $page->getTitle(), $popts, $revId ]
339 } elseif ( $expire <= 0 ) {
340 wfDebug(
"Parser output was marked as uncacheable and has not been saved.\n" );
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.
wfIncrStats( $key, $count=1)
Increment a statistics counter.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
if(! $wgDBerrorLogTZ) $wgRequest
interface is intended to be more or less compatible with the PHP memcached client.
Parser cache specific expiry check.
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
A BagOStuff object with no objects in it.
getDirty( $article, $popts)
Retrieve the ParserOutput from ParserCache, even if it's outdated.
getParserOutputKey( $article, $hash)
const USE_EXPIRED
Use expired data if current data is unavailable.
__construct(BagOStuff $cache, $cacheEpoch='20030516000000')
Setup a cache pathway with a given back-end storage mechanism.
static singleton()
Get an instance of this object.
getCacheStorage()
Get the backend BagOStuff instance that powers the parser cache.
const USE_ANYTHING
Use expired data and data from different revisions, and if all else fails vary on all variable option...
string $cacheEpoch
Anything cached prior to this is invalidated.
save( $parserOutput, $page, $popts, $cacheTime=null, $revId=null)
const USE_CURRENT_ONLY
Constants for self::getKey()
getKey( $article, $popts, $useOutdated=self::USE_ANYTHING)
Generates a key for caching the given article considering the given parser options.
const USE_OUTDATED
Use expired data or data from different revisions if current data is unavailable.
getETag( $article, $popts)
Provides an E-Tag suitable for the whole page.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
processing should stop and the error should be shown to the user * false