MediaWiki  master
ParserCache Class Reference

Cache for ParserOutput objects corresponding to the latest page revisions. More...

Public Member Functions

 __construct (string $name, BagOStuff $cache, string $cacheEpoch, HookContainer $hookContainer, JsonCodec $jsonCodec, IBufferingStatsdDataFactory $stats, LoggerInterface $logger, TitleFactory $titleFactory, WikiPageFactory $wikiPageFactory)
 Setup a cache pathway with a given back-end storage mechanism. More...
 
 deleteOptionsKey (PageRecord $page)
 
 get (PageRecord $page, $popts, $useOutdated=false)
 Retrieve the ParserOutput from ParserCache. More...
 
 getCacheStorage ()
 Get the backend BagOStuff instance that powers the parser cache. More...
 
 getDirty (PageRecord $page, $popts)
 Retrieve the ParserOutput from ParserCache, even if it's outdated. More...
 
 getMetadata (PageRecord $page, int $staleConstraint=self::USE_ANYTHING)
 Returns the ParserCache metadata about the given page considering the given options. More...
 
 makeParserOutputKey (PageRecord $page, ParserOptions $options, array $usedOptions=null)
 Get a key that will be used by the ParserCache to store the content for a given page considering the given options and the array of used options. More...
 
 save (ParserOutput $parserOutput, PageRecord $page, $popts, $cacheTime=null, $revId=null)
 

Public Attributes

const USE_CURRENT_ONLY = 0
 Constants for self::getKey() More...
 
const USE_EXPIRED = 1
 Use expired data if current data is unavailable. More...
 
const USE_OUTDATED = 2
 Use expired data or data from different revisions if current data is unavailable. More...
 

Protected Member Functions

 convertForCache (CacheTime $obj, string $key)
 

Detailed Description

Cache for ParserOutput objects corresponding to the latest page revisions.

The ParserCache is a two-tiered cache backed by BagOStuff which supports varying the stored content on the values of ParserOptions used during a page parse.

First tier is keyed by the page ID and stores ParserCacheMetadata, which contains information about cache expiration and the list of ParserOptions used during the parse of the page. For example, if only 'dateformat' and 'userlang' options were accessed by the parser when producing output for the page, array [ 'dateformat', 'userlang' ] will be stored in the metadata cache. This means none of the other existing options had any effect on the output.

The second tier of the cache contains ParserOutput objects. The key for the second tier is constructed from the page ID and values of those ParserOptions used during a page parse which affected the output. Upon cache lookup, the list of used option names is retrieved from tier 1 cache, and only the values of those options are hashed together with the page ID to produce a key, while the rest of the options are ignored. Following the example above where only [ 'dateformat', 'userlang' ] options changed the parser output for a page, the key will look like 'page_id!dateformat=default:userlang=ru'. Thus any cache lookup with dateformat=default and userlang=ru will hit the same cache entry regardless of the values of the rest of the options, since they were not accessed during a parse and thus did not change the output.

See also
ParserOutput::recordOption()
ParserOutput::getUsedOptions()
ParserOptions::allCacheVaryingOptions()

Definition at line 63 of file ParserCache.php.

Constructor & Destructor Documentation

◆ __construct()

ParserCache::__construct ( string  $name,
BagOStuff  $cache,
string  $cacheEpoch,
HookContainer  $hookContainer,
JsonCodec  $jsonCodec,
IBufferingStatsdDataFactory  $stats,
LoggerInterface  $logger,
TitleFactory  $titleFactory,
WikiPageFactory  $wikiPageFactory 
)

Setup a cache pathway with a given back-end storage mechanism.

This class use an invalidation strategy that is compatible with MultiWriteBagOStuff in async replication mode.

Parameters
string$name
BagOStuff$cache
string$cacheEpochAnything before this timestamp is invalidated
HookContainer$hookContainer
JsonCodec$jsonCodec
IBufferingStatsdDataFactory$stats
LoggerInterface$logger
TitleFactory$titleFactory
WikiPageFactory$wikiPageFactory

Definition at line 140 of file ParserCache.php.

References $cache.

Member Function Documentation

◆ convertForCache()

ParserCache::convertForCache ( CacheTime  $obj,
string  $key 
)
protected
Parameters
CacheTime$obj
string$key
Returns
string|null

Definition at line 596 of file ParserCache.php.

◆ deleteOptionsKey()

ParserCache::deleteOptionsKey ( PageRecord  $page)
Parameters
PageRecord$page
Since
1.28

Definition at line 167 of file ParserCache.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki().

◆ get()

ParserCache::get ( PageRecord  $page,
  $popts,
  $useOutdated = false 
)

Retrieve the ParserOutput from ParserCache.

false if not found or outdated.

Parameters
PageRecord$page
ParserOptions$popts
bool$useOutdated(default false)
Returns
ParserOutput|false

Definition at line 310 of file ParserCache.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), Page\PageIdentity\exists(), Page\PageRecord\isRedirect(), and BagOStuff\READ_VERIFIED.

◆ getCacheStorage()

ParserCache::getCacheStorage ( )

Get the backend BagOStuff instance that powers the parser cache.

Since
1.30
Access: internal
Returns
BagOStuff

Definition at line 510 of file ParserCache.php.

References $cache.

◆ getDirty()

ParserCache::getDirty ( PageRecord  $page,
  $popts 
)

Retrieve the ParserOutput from ParserCache, even if it's outdated.

Parameters
PageRecord$page
ParserOptions$popts
Returns
ParserOutput|false

Definition at line 180 of file ParserCache.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and true.

◆ getMetadata()

ParserCache::getMetadata ( PageRecord  $page,
int  $staleConstraint = self::USE_ANYTHING 
)

Returns the ParserCache metadata about the given page considering the given options.

Note
Which parser options influence the cache key is controlled via ParserOutput::recordOption() or ParserOptions::addExtraKey().
Parameters
PageRecord$page
int$staleConstraintone of the self::USE_ constants
Returns
ParserCacheMetadata|null
Since
1.36

Definition at line 210 of file ParserCache.php.

◆ makeParserOutputKey()

ParserCache::makeParserOutputKey ( PageRecord  $page,
ParserOptions  $options,
array  $usedOptions = null 
)

Get a key that will be used by the ParserCache to store the content for a given page considering the given options and the array of used options.

Warning
The exact format of the key is considered internal and is subject to change, thus should not be used as storage or long-term caching key. This is intended to be used for logging or keying something transient.
Parameters
PageRecord$page
ParserOptions$options
array | null$usedOptionsDefaults to all cache varying options.
Returns
string
Access: internal
Since
1.36

Definition at line 284 of file ParserCache.php.

◆ save()

ParserCache::save ( ParserOutput  $parserOutput,
PageRecord  $page,
  $popts,
  $cacheTime = null,
  $revId = null 
)
Parameters
ParserOutput$parserOutput
PageRecord$page
ParserOptions$popts
string | null$cacheTimeTS_MW timestamp when the cache was generated
int | null$revIdRevision ID that was parsed

Definition at line 393 of file ParserCache.php.

References $title, ParserOutput\addCacheMessage(), MediaWiki\DAO\WikiAwareEntity\assertWiki(), CacheTime\getCacheExpiry(), Page\PageRecord\getLatest(), CacheTime\getUsedOptions(), ParserOutput\hasText(), CacheTime\recordOptions(), CacheTime\setCacheRevisionId(), CacheTime\setCacheTime(), wfTimestampNow(), and BagOStuff\WRITE_ALLOW_SEGMENTS.

Member Data Documentation

◆ USE_CURRENT_ONLY

const ParserCache::USE_CURRENT_ONLY = 0

Constants for self::getKey()

Since
1.30
1.36 the constants were made public Use only current data

Definition at line 71 of file ParserCache.php.

◆ USE_EXPIRED

const ParserCache::USE_EXPIRED = 1

Use expired data if current data is unavailable.

Definition at line 74 of file ParserCache.php.

◆ USE_OUTDATED

const ParserCache::USE_OUTDATED = 2

Use expired data or data from different revisions if current data is unavailable.

Definition at line 77 of file ParserCache.php.


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