MediaWiki  master
CacheTime Class Reference

Parser cache specific expiry check. More...

Inheritance diagram for CacheTime:
Collaboration diagram for CacheTime:

Public Member Functions

 __get ( $name)
 
 __set ( $name, $value)
 
 __wakeup ()
 
 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. More...
 
 getCacheExpiry ()
 Returns the number of seconds after which this object should expire. More...
 
 getCacheRevisionId ()
 
 getCacheTime ()
 
 getUsedOptions ()
 Returns the options from its ParserOptions which have been taken into account to produce the output. More...
 
 isCacheable ()
 
 isDifferentRevision ( $id)
 Return true if this cached output object is for a different revision of the page. More...
 
 recordOption (string $option)
 Tags a parser option for use in the cache key for this parser output. More...
 
 recordOptions (array $options)
 Tags a list of parser option names for use in the cache key for this parser output. More...
 
 setCacheRevisionId ( $id)
 
 setCacheTime ( $t)
 setCacheTime() sets the timestamp expressing when the page has been rendered. More...
 
 updateCacheExpiry ( $seconds)
 Sets the number of seconds after which this object should expire. More...
 

Static Public Member Functions

static newFromJsonArray (JsonUnserializer $unserializer, array $json)
 Creates a new instance of the class and initialized it from the $json array. More...
 

Protected Member Functions

 initFromJson (JsonUnserializer $unserializer, array $jsonData)
 Initialize member fields from an array returned by jsonSerialize(). More...
 
 toJsonArray ()
 Returns a JSON serializable structure representing this CacheTime instance. More...
 

Protected Attributes

int null $mCacheExpiry = null
 Seconds after which the object should expire, use 0 for not cacheable. More...
 
int null $mCacheRevisionId = null
 Revision ID that was parsed. More...
 
string int $mCacheTime = ''
 TS_MW timestamp when this object was generated, or -1 for not cacheable. More...
 
true[] $mParseUsedOptions = []
 ParserOptions which have been taken into account to produce output, option names stored in array keys. More...
 

Detailed Description

Parser cache specific expiry check.

Definition at line 35 of file CacheTime.php.

Member Function Documentation

◆ __get()

CacheTime::__get (   $name)

Reimplemented in ParserOutput.

Definition at line 296 of file CacheTime.php.

References wfDeprecatedMsg().

◆ __set()

CacheTime::__set (   $name,
  $value 
)

Reimplemented in ParserOutput.

Definition at line 311 of file CacheTime.php.

References wfDeprecatedMsg().

◆ __wakeup()

CacheTime::__wakeup ( )

Reimplemented in ParserOutput.

Definition at line 288 of file CacheTime.php.

References recordOptions().

◆ expired()

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 180 of file CacheTime.php.

References $wgCacheEpoch, getCacheExpiry(), getCacheTime(), and isCacheable().

◆ getCacheExpiry()

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 smallest number that was provided to a call of updateCacheExpiry(), and smaller or equal to the value of $wgParserCacheExpireTime.

Returns
int

Implements Parser\ParserCacheMetadata.

Definition at line 142 of file CacheTime.php.

References $mCacheExpiry, and $wgParserCacheExpireTime.

Referenced by expired(), ParserOutput\hasReducedExpiry(), isCacheable(), Parser\RevisionOutputCache\save(), ParserCache\save(), MediaWiki\Storage\PageEditStash\storeStashValue(), and WikiPage\triggerOpportunisticLinksUpdate().

◆ getCacheRevisionId()

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

Implements Parser\ParserCacheMetadata.

Definition at line 96 of file CacheTime.php.

References $mCacheRevisionId.

Referenced by ParserCache\checkOutdated(), Article\doOutputFromParserCache(), and isDifferentRevision().

◆ getCacheTime()

CacheTime::getCacheTime ( )

◆ getUsedOptions()

CacheTime::getUsedOptions ( )

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

Since
1.36
Returns
string[]

Implements Parser\ParserCacheMetadata.

Definition at line 214 of file CacheTime.php.

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

◆ initFromJson()

CacheTime::initFromJson ( JsonUnserializer  $unserializer,
array  $jsonData 
)
protected

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

Parameters
JsonUnserializer$unserializer
array$jsonData

Reimplemented in ParserOutput.

Definition at line 273 of file CacheTime.php.

References recordOptions().

◆ isCacheable()

CacheTime::isCacheable ( )
Returns
bool

Definition at line 168 of file CacheTime.php.

References getCacheExpiry().

Referenced by OutputPage\addParserOutputMetadata(), and expired().

◆ isDifferentRevision()

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 current revision id
Returns
bool

Definition at line 203 of file CacheTime.php.

References getCacheRevisionId().

◆ newFromJsonArray()

static CacheTime::newFromJsonArray ( JsonUnserializer  $unserializer,
array  $json 
)
static

Creates a new instance of the class and initialized it from the $json array.

Parameters
JsonUnserializer$unserializeran instance of JsonUnserializer to use for nested properties if they need special care.
array$json
Returns
JsonUnserializable

Implements MediaWiki\Json\JsonUnserializable.

Reimplemented in ParserOutput.

Definition at line 262 of file CacheTime.php.

◆ recordOption()

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 230 of file CacheTime.php.

◆ recordOptions()

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 240 of file CacheTime.php.

Referenced by __wakeup(), initFromJson(), and ParserCache\save().

◆ setCacheRevisionId()

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

Definition at line 104 of file CacheTime.php.

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

◆ setCacheTime()

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 79 of file CacheTime.php.

References $t, wfDeprecatedMsg(), and wfSetVar().

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

◆ toJsonArray()

CacheTime::toJsonArray ( )
protected

Returns a JSON serializable structure representing this CacheTime instance.

See also
newFromJson()
Returns
array

Reimplemented in ParserOutput.

Definition at line 253 of file CacheTime.php.

References $mCacheExpiry, $mCacheRevisionId, $mCacheTime, and $mParseUsedOptions.

◆ updateCacheExpiry()

CacheTime::updateCacheExpiry (   $seconds)

Sets 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. The value returned by getCacheExpiry is smaller or equal to the smallest number that was provided as an argument to updateCacheExpiry().

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

Definition at line 125 of file CacheTime.php.

Referenced by ParserOutput\finalizeAdaptiveCacheExpiry(), Parser\RevisionOutputCache\save(), and ParserOutput\updateRuntimeAdaptiveExpiry().

Member Data Documentation

◆ $mCacheExpiry

int null CacheTime::$mCacheExpiry = null
protected

Seconds after which the object should expire, use 0 for not cacheable.

Used in ParserCache.

Definition at line 55 of file CacheTime.php.

Referenced by getCacheExpiry(), and toJsonArray().

◆ $mCacheRevisionId

int null CacheTime::$mCacheRevisionId = null
protected

Revision ID that was parsed.

Definition at line 60 of file CacheTime.php.

Referenced by getCacheRevisionId(), and toJsonArray().

◆ $mCacheTime

string int CacheTime::$mCacheTime = ''
protected

TS_MW timestamp when this object was generated, or -1 for not cacheable.

Used in ParserCache.

Definition at line 49 of file CacheTime.php.

Referenced by getCacheTime(), and toJsonArray().

◆ $mParseUsedOptions

true [] CacheTime::$mParseUsedOptions = []
protected

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

Definition at line 43 of file CacheTime.php.

Referenced by toJsonArray().


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