MediaWiki
master
|
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, $useJson=false) | |
Setup a cache pathway with a given back-end storage mechanism. More... | |
deleteOptionsKey (WikiPage $wikiPage) | |
get (WikiPage $wikiPage, $popts, $useOutdated=false) | |
Retrieve the ParserOutput from ParserCache. More... | |
getCacheStorage () | |
Get the backend BagOStuff instance that powers the parser cache. More... | |
getDirty (WikiPage $wikiPage, $popts) | |
Retrieve the ParserOutput from ParserCache, even if it's outdated. More... | |
getETag (WikiPage $wikiPage, $popts) | |
Provides an E-Tag suitable for the whole page. More... | |
getKey (WikiPage $wikiPage, $popts, $useOutdated=self::USE_ANYTHING) | |
Generates a key for caching the given page considering the given parser options. More... | |
getMetadata (WikiPage $wikiPage, int $staleConstraint=self::USE_ANYTHING) | |
Returns the ParserCache metadata about the given page considering the given options. More... | |
makeParserOutputKey (WikiPage $wikiPage, 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, WikiPage $wikiPage, $popts, $cacheTime=null, $revId=null) | |
setJsonSupport (bool $readJson, bool $writeJson) | |
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... | |
Private Member Functions | |
checkExpired (CacheTime $entry, WikiPage $wikiPage, int $staleConstraint, string $cacheTier) | |
Check if $entry expired for $wikiPage given the $staleConstraint when fetching from $cacheTier. More... | |
checkOutdated (CacheTime $entry, WikiPage $wikiPage, int $staleConstraint, string $cacheTier) | |
Check if $entry belongs to the latest revision of $wikiPage given $staleConstraint when fetched from $cacheTier. More... | |
encodeAsJson (CacheTime $obj, string $key) | |
incrementStats (WikiPage $wikiPage, $metricSuffix) | |
makeMetadataKey (WikiPage $wikiPage) | |
restoreFromJson (string $jsonData, string $key, string $expectedClass) | |
Private Attributes | |
BagOStuff | $cache |
string | $cacheEpoch |
Anything cached prior to this is invalidated. More... | |
HookRunner | $hookRunner |
JsonCodec | $jsonCodec |
LoggerInterface | $logger |
string | $name |
The name of this ParserCache. More... | |
bool | $readJson = false |
IBufferingStatsdDataFactory | $stats |
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. More... | |
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 61 of file ParserCache.php.
ParserCache::__construct | ( | string | $name, |
BagOStuff | $cache, | ||
string | $cacheEpoch, | ||
HookContainer | $hookContainer, | ||
JsonCodec | $jsonCodec, | ||
IBufferingStatsdDataFactory | $stats, | ||
LoggerInterface | $logger, | ||
$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 | |
bool | $useJson | Temporary feature flag, remove before 1.36 is released. |
Definition at line 135 of file ParserCache.php.
References $cache, $cacheEpoch, $jsonCodec, $logger, $name, and $stats.
|
private |
Check if $entry expired for $wikiPage given the $staleConstraint when fetching from $cacheTier.
CacheTime | $entry | |
WikiPage | $wikiPage | |
int | $staleConstraint | One of USE_* constants. |
string | $cacheTier |
Definition at line 577 of file ParserCache.php.
References CacheTime\getCacheTime(), WikiPage\getTouched(), and incrementStats().
Referenced by get(), and getMetadata().
|
private |
Check if $entry belongs to the latest revision of $wikiPage given $staleConstraint when fetched from $cacheTier.
CacheTime | $entry | |
WikiPage | $wikiPage | |
int | $staleConstraint | One of USE_* constants. |
string | $cacheTier |
Definition at line 605 of file ParserCache.php.
References CacheTime\getCacheRevisionId(), WikiPage\getLatest(), and incrementStats().
Referenced by get(), and getMetadata().
ParserCache::deleteOptionsKey | ( | WikiPage | $wikiPage | ) |
WikiPage | $wikiPage |
Definition at line 173 of file ParserCache.php.
References makeMetadataKey().
|
private |
CacheTime | $obj | |
string | $key |
Definition at line 661 of file ParserCache.php.
Referenced by save().
ParserCache::get | ( | WikiPage | $wikiPage, |
$popts, | |||
$useOutdated = false |
|||
) |
Retrieve the ParserOutput from ParserCache.
false if not found or outdated.
WikiPage | $wikiPage | |
ParserOptions | $popts | |
bool | $useOutdated | (default false) |
Definition at line 369 of file ParserCache.php.
References checkExpired(), checkOutdated(), WikiPage\checkTouched(), getMetadata(), incrementStats(), makeParserOutputKey(), BagOStuff\READ_VERIFIED, restoreFromJson(), USE_CURRENT_ONLY, and USE_OUTDATED.
ParserCache::getCacheStorage | ( | ) |
Get the backend BagOStuff instance that powers the parser cache.
Definition at line 564 of file ParserCache.php.
References $cache.
ParserCache::getDirty | ( | WikiPage | $wikiPage, |
$popts | |||
) |
Retrieve the ParserOutput from ParserCache, even if it's outdated.
WikiPage | $wikiPage | |
ParserOptions | $popts |
Definition at line 204 of file ParserCache.php.
References true.
Referenced by RefreshLinksJob\getParserOutputFromCache().
ParserCache::getETag | ( | WikiPage | $wikiPage, |
$popts | |||
) |
Provides an E-Tag suitable for the whole page.
Note that $wikiPage is just the main wikitext. The E-Tag has to be unique to the whole page, even if the article itself is the same, so it uses the complete set of user options. We don't want to use the preference of a different user on a message just because it wasn't used in $wikiPage. For example give a Chinese interface to a user with English preferences. That's why we take into account all user options. (r70809 CR)
WikiPage | $wikiPage | |
ParserOptions | $popts |
Definition at line 192 of file ParserCache.php.
References WikiPage\getTouched(), makeParserOutputKey(), and wfDeprecated().
ParserCache::getKey | ( | WikiPage | $wikiPage, |
$popts, | |||
$useOutdated = self::USE_ANYTHING |
|||
) |
Generates a key for caching the given page considering the given parser options.
WikiPage | $wikiPage | |
ParserOptions | $popts | |
int | bool | $useOutdated | One of the USE constants. For backwards compatibility, boolean false is treated as USE_CURRENT_ONLY and boolean true is treated as USE_ANYTHING. |
Definition at line 240 of file ParserCache.php.
References ParserOptions\allCacheVaryingOptions(), getMetadata(), makeParserOutputKey(), ParserOptions\newFromUser(), USE_ANYTHING, USE_CURRENT_ONLY, and wfDeprecated().
ParserCache::getMetadata | ( | WikiPage | $wikiPage, |
int | $staleConstraint = self::USE_ANYTHING |
||
) |
Returns the ParserCache metadata about the given page considering the given options.
WikiPage | $wikiPage | |
int | $staleConstraint | one of the self::USE_ constants |
Definition at line 279 of file ParserCache.php.
References checkExpired(), checkOutdated(), incrementStats(), makeMetadataKey(), BagOStuff\READ_VERIFIED, and restoreFromJson().
|
private |
WikiPage | $wikiPage | |
string | $metricSuffix |
Definition at line 213 of file ParserCache.php.
References WikiPage\getContentModel().
Referenced by checkExpired(), checkOutdated(), get(), getMetadata(), and save().
|
private |
WikiPage | $wikiPage |
Definition at line 322 of file ParserCache.php.
References WikiPage\getId().
Referenced by deleteOptionsKey(), getMetadata(), and save().
ParserCache::makeParserOutputKey | ( | WikiPage | $wikiPage, |
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.
WikiPage | $wikiPage | |
ParserOptions | $options | |
array | null | $usedOptions | Defaults to all cache verying options. |
Definition at line 342 of file ParserCache.php.
References $wgRequest, ParserOptions\allCacheVaryingOptions(), WikiPage\getId(), WikiPage\getTitle(), and ParserOptions\optionsHash().
|
private |
string | $jsonData | |
string | $key | |
string | $expectedClass |
Definition at line 641 of file ParserCache.php.
Referenced by get(), and getMetadata().
ParserCache::save | ( | ParserOutput | $parserOutput, |
WikiPage | $wikiPage, | ||
$popts, | |||
$cacheTime = null , |
|||
$revId = null |
|||
) |
ParserOutput | $parserOutput | |
WikiPage | $wikiPage | |
ParserOptions | $popts | |
string | null | $cacheTime | TS_MW timestamp when the cache was generated |
int | null | $revId | Revision ID that was parsed |
Definition at line 444 of file ParserCache.php.
References ParserOutput\addCacheMessage(), encodeAsJson(), CacheTime\getCacheExpiry(), WikiPage\getRevisionRecord(), WikiPage\getTimestamp(), WikiPage\getTitle(), CacheTime\getUsedOptions(), ParserOutput\hasText(), incrementStats(), makeMetadataKey(), makeParserOutputKey(), CacheTime\recordOptions(), CacheTime\setCacheRevisionId(), CacheTime\setCacheTime(), ParserOutput\setTimestamp(), wfTimestampNow(), and BagOStuff\WRITE_ALLOW_SEGMENTS.
ParserCache::setJsonSupport | ( | bool | $readJson, |
bool | $writeJson | ||
) |
bool | $readJson | |
bool | $writeJson |
Definition at line 630 of file ParserCache.php.
References $readJson, and $writeJson.
|
private |
Definition at line 87 of file ParserCache.php.
Referenced by __construct(), and getCacheStorage().
|
private |
Anything cached prior to this is invalidated.
Definition at line 94 of file ParserCache.php.
Referenced by __construct().
|
private |
Definition at line 97 of file ParserCache.php.
|
private |
Definition at line 100 of file ParserCache.php.
Referenced by __construct().
|
private |
Definition at line 106 of file ParserCache.php.
Referenced by __construct().
|
private |
The name of this ParserCache.
Used as a root of the cache key.
Definition at line 84 of file ParserCache.php.
Referenced by __construct().
|
private |
Definition at line 118 of file ParserCache.php.
Referenced by setJsonSupport().
|
private |
Definition at line 103 of file ParserCache.php.
Referenced by __construct().
|
private |
Definition at line 112 of file ParserCache.php.
Referenced by setJsonSupport().
|
private |
Use expired data and data from different revisions, and if all else fails vary on all variable options.
Definition at line 81 of file ParserCache.php.
Referenced by getKey().
const ParserCache::USE_CURRENT_ONLY = 0 |
Constants for self::getKey()
Definition at line 69 of file ParserCache.php.
const ParserCache::USE_EXPIRED = 1 |
Use expired data if current data is unavailable.
Definition at line 72 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 75 of file ParserCache.php.
Referenced by get().