MediaWiki REL1_37
|
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, $useJson=false) | |
Setup a cache pathway with a given back-end storage mechanism. | |
deleteOptionsKey (PageRecord $page) | |
get (PageRecord $page, $popts, $useOutdated=false) | |
Retrieve the ParserOutput from ParserCache. | |
getCacheStorage () | |
Get the backend BagOStuff instance that powers the parser cache. | |
getDirty (PageRecord $page, $popts) | |
Retrieve the ParserOutput from ParserCache, even if it's outdated. | |
getMetadata (PageRecord $page, int $staleConstraint=self::USE_ANYTHING) | |
Returns the ParserCache metadata about the given page considering the given options. | |
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. | |
save (ParserOutput $parserOutput, PageRecord $page, $popts, $cacheTime=null, $revId=null) | |
setJsonSupport (bool $readJson, bool $writeJson) | |
Public Attributes | |
const | USE_CURRENT_ONLY = 0 |
Constants for self::getKey() | |
const | USE_EXPIRED = 1 |
Use expired data if current data is unavailable. | |
const | USE_OUTDATED = 2 |
Use expired data or data from different revisions if current data is unavailable. | |
Private Member Functions | |
checkExpired (CacheTime $entry, PageRecord $page, int $staleConstraint, string $cacheTier) | |
Check if $entry expired for $page given the $staleConstraint when fetching from $cacheTier. | |
checkOutdated (CacheTime $entry, PageRecord $page, int $staleConstraint, string $cacheTier) | |
Check if $entry belongs to the latest revision of $page given $staleConstraint when fetched from $cacheTier. | |
encodeAsJson (CacheTime $obj, string $key) | |
incrementStats (PageRecord $page, $metricSuffix) | |
makeMetadataKey (PageRecord $page) | |
restoreFromJson (string $jsonData, string $key, string $expectedClass) | |
Private Attributes | |
BagOStuff | $cache |
string | $cacheEpoch |
Anything cached prior to this is invalidated. | |
HookRunner | $hookRunner |
JsonCodec | $jsonCodec |
LoggerInterface | $logger |
BagOStuff | $metadataProcCache |
small in-process cache to store metadata. | |
string | $name |
The name of this ParserCache. | |
bool | $readJson = false |
IBufferingStatsdDataFactory | $stats |
TitleFactory | $titleFactory |
WikiPageFactory | $wikiPageFactory |
bool | $writeJson = false |
const | USE_ANYTHING = 3 |
Use expired data and data from different revisions, and if all else fails vary on all variable options. | |
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.
Definition at line 63 of file ParserCache.php.
ParserCache::__construct | ( | string | $name, |
BagOStuff | $cache, | ||
string | $cacheEpoch, | ||
HookContainer | $hookContainer, | ||
JsonCodec | $jsonCodec, | ||
IBufferingStatsdDataFactory | $stats, | ||
LoggerInterface | $logger, | ||
TitleFactory | $titleFactory, | ||
WikiPageFactory | $wikiPageFactory, | ||
$useJson = false |
|||
) |
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.
string | $name | |
BagOStuff | $cache | |
string | $cacheEpoch | Anything before this timestamp is invalidated |
HookContainer | $hookContainer | |
JsonCodec | $jsonCodec | |
IBufferingStatsdDataFactory | $stats | |
LoggerInterface | $logger | |
TitleFactory | $titleFactory | |
WikiPageFactory | $wikiPageFactory | |
bool | $useJson | Temporary feature flag, remove before 1.36 is released. |
Definition at line 153 of file ParserCache.php.
References $cache.
|
private |
Check if $entry expired for $page given the $staleConstraint when fetching from $cacheTier.
CacheTime | $entry | |
PageRecord | $page | |
int | $staleConstraint | One of USE_* constants. |
string | $cacheTier |
Definition at line 542 of file ParserCache.php.
References CacheTime\getCacheTime(), and MediaWiki\Page\PageRecord\getTouched().
|
private |
Check if $entry belongs to the latest revision of $page given $staleConstraint when fetched from $cacheTier.
CacheTime | $entry | |
PageRecord | $page | |
int | $staleConstraint | One of USE_* constants. |
string | $cacheTier |
Definition at line 570 of file ParserCache.php.
References CacheTime\getCacheRevisionId().
ParserCache::deleteOptionsKey | ( | PageRecord | $page | ) |
PageRecord | $page |
Definition at line 183 of file ParserCache.php.
References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and makeMetadataKey().
|
private |
CacheTime | $obj | |
string | $key |
Definition at line 626 of file ParserCache.php.
ParserCache::get | ( | PageRecord | $page, |
$popts, | |||
$useOutdated = false |
|||
) |
Retrieve the ParserOutput from ParserCache.
false if not found or outdated.
PageRecord | $page | |
ParserOptions | $popts | |
bool | $useOutdated | (default false) |
Definition at line 328 of file ParserCache.php.
References MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Page\PageIdentity\exists(), and MediaWiki\Page\PageRecord\isRedirect().
ParserCache::getCacheStorage | ( | ) |
Get the backend BagOStuff instance that powers the parser cache.
Definition at line 529 of file ParserCache.php.
References $cache.
ParserCache::getDirty | ( | PageRecord | $page, |
$popts | |||
) |
Retrieve the ParserOutput from ParserCache, even if it's outdated.
PageRecord | $page | |
ParserOptions | $popts |
Definition at line 196 of file ParserCache.php.
References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and true.
Referenced by RefreshLinksJob\getParserOutputFromCache().
ParserCache::getMetadata | ( | PageRecord | $page, |
int | $staleConstraint = self::USE_ANYTHING |
||
) |
Returns the ParserCache metadata about the given page considering the given options.
PageRecord | $page | |
int | $staleConstraint | one of the self::USE_ constants |
Definition at line 226 of file ParserCache.php.
References makeMetadataKey().
|
private |
PageRecord | $page | |
string | $metricSuffix |
Definition at line 206 of file ParserCache.php.
|
private |
PageRecord | $page |
Definition at line 280 of file ParserCache.php.
Referenced by deleteOptionsKey(), and getMetadata().
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.
PageRecord | $page | |
ParserOptions | $options | |
array | null | $usedOptions | Defaults to all cache verying options. |
Definition at line 300 of file ParserCache.php.
|
private |
string | $jsonData | |
string | $key | |
string | $expectedClass |
Definition at line 606 of file ParserCache.php.
ParserCache::save | ( | ParserOutput | $parserOutput, |
PageRecord | $page, | ||
$popts, | |||
$cacheTime = null , |
|||
$revId = null |
|||
) |
ParserOutput | $parserOutput | |
PageRecord | $page | |
ParserOptions | $popts | |
string | null | $cacheTime | TS_MW timestamp when the cache was generated |
int | null | $revId | Revision ID that was parsed |
Definition at line 411 of file ParserCache.php.
References $title, ParserOutput\addCacheMessage(), MediaWiki\DAO\WikiAwareEntity\assertWiki(), CacheTime\getCacheExpiry(), MediaWiki\Page\PageRecord\getLatest(), CacheTime\getUsedOptions(), ParserOutput\hasText(), CacheTime\recordOptions(), CacheTime\setCacheRevisionId(), CacheTime\setCacheTime(), and wfTimestampNow().
ParserCache::setJsonSupport | ( | bool | $readJson, |
bool | $writeJson | ||
) |
bool | $readJson | |
bool | $writeJson |
Definition at line 595 of file ParserCache.php.
|
private |
Definition at line 89 of file ParserCache.php.
|
private |
Anything cached prior to this is invalidated.
Definition at line 96 of file ParserCache.php.
|
private |
Definition at line 99 of file ParserCache.php.
|
private |
Definition at line 102 of file ParserCache.php.
|
private |
Definition at line 108 of file ParserCache.php.
|
private |
small in-process cache to store metadata.
It's needed multiple times during the request, for example to build a PoolWorkArticleView key, and then to fetch the actual ParserCache entry.
Definition at line 122 of file ParserCache.php.
|
private |
The name of this ParserCache.
Used as a root of the cache key.
Definition at line 86 of file ParserCache.php.
|
private |
Definition at line 134 of file ParserCache.php.
|
private |
Definition at line 105 of file ParserCache.php.
|
private |
Definition at line 111 of file ParserCache.php.
|
private |
Definition at line 114 of file ParserCache.php.
|
private |
Definition at line 128 of file ParserCache.php.
|
private |
Use expired data and data from different revisions, and if all else fails vary on all variable options.
Definition at line 83 of file ParserCache.php.
const ParserCache::USE_CURRENT_ONLY = 0 |
Constants for self::getKey()
Definition at line 71 of file ParserCache.php.
const ParserCache::USE_EXPIRED = 1 |
Use expired data if current data is unavailable.
Definition at line 74 of file ParserCache.php.
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.