Go to the documentation of this file.
67 return MediaWikiServices::getInstance()->getParserCache();
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() );
134 "--" .
$article->getTouched() .
'"';
169 if ( is_bool( $useOutdated ) ) {
173 if ( $popts instanceof
User ) {
174 wfWarn(
"Use of outdated prototype ParserCache::getKey( &\$article, &\$user )\n" );
180 $optionsKey = $this->mMemc->get(
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() )
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 ) {
214 $popts->optionsHash( $usedOptions,
$article->getTitle() )
229 $canCache =
$article->checkTouched();
238 $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
240 if ( $parserOutputKey ===
false ) {
249 wfDebug(
"ParserOutput cache miss.\n" );
254 wfDebug(
"ParserOutput cache found.\n" );
259 $value->setEditSectionTokens( $popts->getEditSection() );
261 $wikiPage = method_exists(
$article,
'getPage' )
265 if ( !$useOutdated &&
$value->expired( $touched ) ) {
267 $cacheTime =
$value->getCacheTime();
269 "ParserOutput key expired, touched $touched, "
270 .
"epoch {$this->cacheEpoch}, cached $cacheTime\n" );
272 } elseif ( !$useOutdated &&
$value->isDifferentRevision(
$article->getLatest() ) ) {
275 $cachedRevId =
$value->getCacheRevisionId();
277 "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
281 Hooks::run(
'RejectParserCacheValue', [
$value, $wikiPage, $popts ] ) ===
false
285 "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"
302 public function save( $parserOutput, $page, $popts, $cacheTime =
null, $revId =
null ) {
303 $expire = $parserOutput->getCacheExpiry();
307 $revision = $page->getRevision();
308 $revId = $revision ? $revision->getId() :
null;
312 $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
315 $optionsKey->setCacheTime( $cacheTime );
316 $parserOutput->setCacheTime( $cacheTime );
317 $optionsKey->setCacheRevisionId( $revId );
318 $parserOutput->setCacheRevisionId( $revId );
321 $popts->optionsHash( $optionsKey->mUsedOptions, $page->getTitle() ) );
324 $parserOutput->setTimestamp( $page->getTimestamp() );
326 $msg =
"Saved in parser cache with key $parserOutputKey" .
327 " and timestamp $cacheTime" .
328 " and revision id $revId" .
331 $parserOutput->mText .=
"\n<!-- $msg -->\n";
335 $this->mMemc->set( $parserOutputKey, $parserOutput, $expire );
338 $this->mMemc->set( $this->
getOptionsKey( $page ), $optionsKey, $expire );
341 'ParserCacheSaveComplete',
342 [ $this, $parserOutput, $page->getTitle(), $popts, $revId ]
344 } elseif ( $expire <= 0 ) {
345 wfDebug(
"Parser output was marked as uncacheable and has not been saved.\n" );
const USE_EXPIRED
Use expired data if current data is unavailable.
processing should stop and the error should be shown to the user * false
Parser cache specific expiry check.
A BagOStuff object with no objects in it.
getETag( $article, $popts)
Provides an E-Tag suitable for the whole page.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
interface is intended to be more or less compatible with the PHP memcached client.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
save( $parserOutput, $page, $popts, $cacheTime=null, $revId=null)
const USE_ANYTHING
Use expired data and data from different revisions, and if all else fails vary on all variable option...
wfIncrStats( $key, $count=1)
Increment a statistics counter.
getDirty( $article, $popts)
Retrieve the ParserOutput from ParserCache, even if it's outdated.
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
when a variable name is used in a it is silently declared as a new masking the global
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getKey( $article, $popts, $useOutdated=self::USE_ANYTHING)
Generates a key for caching the given article considering the given parser options.
getCacheStorage()
Get the backend BagOStuff instance that powers the parser cache.
static singleton()
Get an instance of this object.
const USE_CURRENT_ONLY
Constants for self::getKey()
getParserOutputKey( $article, $hash)
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
string $cacheEpoch
Anything cached prior to this is invalidated.
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
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
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
if(! $wgDBerrorLogTZ) $wgRequest
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
const USE_OUTDATED
Use expired data or data from different revisions if current data is unavailable.
__construct(BagOStuff $cache, $cacheEpoch='20030516000000')
Setup a cache pathway with a given back-end storage mechanism.
static newFromUser( $user)
Get a ParserOptions object from a given user.