MediaWiki master
MediaWiki\Parser\CacheTime Class Reference

Parser cache specific expiry check. More...

Inherits MediaWiki\Parser\ParserCacheMetadata, and JsonCodecable.

Inherited by MediaWiki\Parser\ParserOutput.

Collaboration diagram for MediaWiki\Parser\CacheTime:

Public Member Functions

 expired ( $touched)
 Return true if this cached output object predates the global or per-article cache invalidation timestamps, or if it comes from an incompatible older version.
 
 getCacheExpiry ()
 Returns the number of seconds after which this object should expire.
 
 getCacheExpirySource ()
 
 getCacheRevisionId ()
 
 getCacheTime ()
 
 getUsedOptions ()
 Returns the options from its ParserOptions which have been taken into account to produce the output.
 
 hasCacheTime ()
 
 isCacheable ()
 
 isDifferentRevision ( $id)
 Return true if this cached output object is for a different revision of the page.
 
 recordOption (string $option)
 Tags a parser option for use in the cache key for this parser output.
 
 recordOptions (array $options)
 Tags a list of parser option names for use in the cache key for this parser output.
 
 setCacheRevisionId ( $id)
 
 setCacheTime ( $t)
 setCacheTime() sets the timestamp expressing when the page has been rendered.
 
 toJsonArray ()
 Returns a JSON serializable structure representing this CacheTime instance.
 
 updateCacheExpiry ( $seconds, ?string $source=null)
 Reduce the number of seconds after which this object should expire.
 

Static Public Member Functions

static newFromJsonArray (array $json)
 

Protected Member Functions

 initFromJson (array $jsonData)
 Initialize member fields from an array returned by toJsonArray().
 

Protected Attributes

int int null $mCacheExpiry = null
 Seconds after which the object should expire, use 0 for not cacheable and null for "the default cache expiration time" (which is assumed to be greater than zero).
 
string string null $mCacheExpirySource = null
 Human-readable label identifying what caused the current cache expiry value (e.g.
 
int int null $mCacheRevisionId = null
 Revision ID that was parsed.
 
string string $mCacheTime = ''
 TS::MW timestamp when this object was generated, or '' if not yet set.
 
array array< string, true > $mParseUsedOptions = []
 ParserOptions which have been taken into account to produce output, option names stored in array keys.
 

Detailed Description

Parser cache specific expiry check.

Definition at line 25 of file CacheTime.php.

Member Function Documentation

◆ expired()

MediaWiki\Parser\CacheTime::expired ( $touched)

Return true if this cached output object predates the global or per-article cache invalidation timestamps, or if it comes from an incompatible older version.

Parameters
string$touchedThe affected article's last touched timestamp
Returns
bool

Definition at line 192 of file CacheTime.php.

◆ getCacheExpiry()

MediaWiki\Parser\CacheTime::getCacheExpiry ( )

Returns the number of seconds after which this object should expire.

This method is used by ParserCache to determine how long the ParserOutput can be cached. The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime(). The value returned by getCacheExpiry() is smaller or equal to the value of $wgParserCacheExpireTime and influenced by the values provided to calls to updateCacheExpiry(), but child classes may adjust the raw value: for example, to add minimums, dynamic adjustments, or reductions to the default expiry based on output properties.

Note
Use the protected $mCacheExpiry property to access the "real" minimum value provided to updateCacheExpiry, but as this should generally not be accessed outside this class no public getter method has been provided.
This method should return 0 if and only if ::isCacheable() returns false.

Implements MediaWiki\Parser\ParserCacheMetadata.

Reimplemented in MediaWiki\Parser\ParserOutput.

Definition at line 157 of file CacheTime.php.

◆ getCacheExpirySource()

MediaWiki\Parser\CacheTime::getCacheExpirySource ( )
Returns
string|null Human-readable label identifying what caused the current cache expiry, or null if no source was recorded.
See also
updateCacheExpiry()
Since
1.46

Definition at line 171 of file CacheTime.php.

Referenced by MediaWiki\Parser\Parser\makeLimitReport(), and MediaWiki\Parser\ParserCache\save().

◆ getCacheRevisionId()

MediaWiki\Parser\CacheTime::getCacheRevisionId ( )
Since
1.23
Returns
int|null Revision id, if any was set

Implements MediaWiki\Parser\ParserCacheMetadata.

Definition at line 100 of file CacheTime.php.

Referenced by MediaWiki\Parser\RevisionOutputCache\save(), and MediaWiki\Parser\ParserCache\save().

◆ getCacheTime()

◆ getUsedOptions()

MediaWiki\Parser\CacheTime::getUsedOptions ( )

Returns the options from its ParserOptions which have been taken into account to produce the output.

Since
1.36
Returns
string[]

Implements MediaWiki\Parser\ParserCacheMetadata.

Definition at line 226 of file CacheTime.php.

Referenced by MediaWiki\Parser\ParserObserver\notifyParse(), and MediaWiki\Parser\ParserCache\save().

◆ hasCacheTime()

MediaWiki\Parser\CacheTime::hasCacheTime ( )
Returns
bool true if a cache time has been set

Definition at line 73 of file CacheTime.php.

Referenced by MediaWiki\Parser\ParserCache\save().

◆ initFromJson()

MediaWiki\Parser\CacheTime::initFromJson ( array $jsonData)
protected

Initialize member fields from an array returned by toJsonArray().

Parameters
array$jsonData

Reimplemented in MediaWiki\Parser\ParserOutput.

Definition at line 288 of file CacheTime.php.

◆ isCacheable()

MediaWiki\Parser\CacheTime::isCacheable ( )
Returns
bool

Definition at line 178 of file CacheTime.php.

Referenced by MediaWiki\Output\OutputPage\addParserOutputMetadata().

◆ isDifferentRevision()

MediaWiki\Parser\CacheTime::isDifferentRevision ( $id)

Return true if this cached output object is for a different revision of the page.

Todo
We always return false if $this->getCacheRevisionId() is null; this prevents invalidating the whole parser cache when this change is deployed. Someday that should probably be changed.
Since
1.23
Parameters
int$idThe affected article's latest revision id
Returns
bool

Definition at line 215 of file CacheTime.php.

◆ newFromJsonArray()

static MediaWiki\Parser\CacheTime::newFromJsonArray ( array $json)
static

Reimplemented in MediaWiki\Parser\ParserOutput.

Definition at line 278 of file CacheTime.php.

◆ recordOption()

MediaWiki\Parser\CacheTime::recordOption ( string $option)

Tags a parser option for use in the cache key for this parser output.

Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState(). The information gathered here is available via getUsedOptions(), and is used by ParserCache::save().

See also
ParserCache::getMetadata
ParserCache::save
ParserOptions::addExtraKey
ParserOptions::optionsHash
Parameters
string$option

Definition at line 242 of file CacheTime.php.

◆ recordOptions()

MediaWiki\Parser\CacheTime::recordOptions ( array $options)

Tags a list of parser option names for use in the cache key for this parser output.

See also
recordOption()
Parameters
string[]$options

Definition at line 252 of file CacheTime.php.

Referenced by MediaWiki\Parser\ParserCache\save().

◆ setCacheRevisionId()

MediaWiki\Parser\CacheTime::setCacheRevisionId ( $id)
Since
1.23
Parameters
int | null$idRevision ID

Definition at line 108 of file CacheTime.php.

Referenced by MediaWiki\Parser\RevisionOutputCache\save(), and MediaWiki\Parser\ParserCache\save().

◆ setCacheTime()

MediaWiki\Parser\CacheTime::setCacheTime ( $t)

setCacheTime() sets the timestamp expressing when the page has been rendered.

This does not control expiry, see updateCacheExpiry() for that!

Parameters
string$tTS::MW timestamp
Returns
string

Definition at line 83 of file CacheTime.php.

References wfDeprecated().

Referenced by MediaWiki\Parser\RevisionOutputCache\save(), and MediaWiki\Parser\ParserCache\save().

◆ toJsonArray()

MediaWiki\Parser\CacheTime::toJsonArray ( )

Returns a JSON serializable structure representing this CacheTime instance.

See also
::newFromJsonArray()
Returns
array

Reimplemented in MediaWiki\Parser\ParserOutput.

Definition at line 265 of file CacheTime.php.

◆ updateCacheExpiry()

MediaWiki\Parser\CacheTime::updateCacheExpiry ( $seconds,
?string $source = null )

Reduce the number of seconds after which this object should expire.

This value is used with the ParserCache. If called with a value greater than the value provided at any previous call, the new call has no effect.

Avoid using 0 if at all possible. Consider JavaScript for highly dynamic content.

NOTE: Beware that reducing the TTL for reasons that do not relate to "dynamic content", may have the side-effect of incurring more RefreshLinksJob executions. See also WikiPage::triggerOpportunisticLinksUpdate.

Parameters
int$seconds
string | null$sourceHuman-readable label identifying what is responsible for this TTL (e.g. a magic word or template name). Recorded only when the expiry is actually lowered.
Since
1.46
Deprecated
since 1.46 Calling this method without $source.

Definition at line 131 of file CacheTime.php.

References $source.

Referenced by MediaWiki\Parser\RevisionOutputCache\save().

Member Data Documentation

◆ $mCacheExpiry

int int null MediaWiki\Parser\CacheTime::$mCacheExpiry = null
protected

Seconds after which the object should expire, use 0 for not cacheable and null for "the default cache expiration time" (which is assumed to be greater than zero).

Used in ParserCache.

Definition at line 46 of file CacheTime.php.

◆ $mCacheExpirySource

string string null MediaWiki\Parser\CacheTime::$mCacheExpirySource = null
protected

Human-readable label identifying what caused the current cache expiry value (e.g.

"Template:Foo (currentday)"). Updated only when updateCacheExpiry() actually lowers the TTL.

Definition at line 58 of file CacheTime.php.

◆ $mCacheRevisionId

int int null MediaWiki\Parser\CacheTime::$mCacheRevisionId = null
protected

Revision ID that was parsed.

Definition at line 51 of file CacheTime.php.

◆ $mCacheTime

string string MediaWiki\Parser\CacheTime::$mCacheTime = ''
protected

TS::MW timestamp when this object was generated, or '' if not yet set.

Used in ParserCache.

Definition at line 38 of file CacheTime.php.

Referenced by MediaWiki\Parser\CacheTime\getCacheTime().

◆ $mParseUsedOptions

array array<string,true> MediaWiki\Parser\CacheTime::$mParseUsedOptions = []
protected

ParserOptions which have been taken into account to produce output, option names stored in array keys.

Definition at line 32 of file CacheTime.php.


The documentation for this class was generated from the following file: