Manual:Parser cache

The parser cache is responsible for caching the rendered output of a wiki page. It is the primary caching mechanism for serving page views in MediaWiki (not counting any web-cache such as varnish in front of MediaWiki).

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:
 * The case is split (varied) based on ParserOptions. This uses a two-tiered system
 * The Parser cache is semi-permanent. A ParserCache based on "canonical" ParserOptions entry is pre-generated upon save, and re-generated using the LinksUpdate mechanism.
 * Parser cache entries can be invalidated individually by bumping the page_touched field, or collectively by bumping the $wgCacheEpoch setting.
 * The cache includes meta-data extracted by core and defined by extensions
 * Since 1.36, the cache uses JSON serialization. Before that, it relied on PHP serialization.
 * Since 1.36, it is possible to have multiple ParserCache instances side by side. ParserCache instances are managed by the ParserCacheFactory which can be obtained from MediaWikiServices.
 * The main ParserCache covers the latest revision of a page. Since 1.36, a similar cache exists for old revisions of a page, the RevisionOutputCache. Instances of RevisionOutputCache are managed by the ParserCacheFactory which can be obtained from MediaWikiServices. The intent of RevisionOutputCache is to protect against load spikes caused by certain old revisions of a page being viewed by a large number of users, typically due to an external "deep" link to that revision. As such, this cache is usually configured with a short expiry time (per default, one hour), and typically have a low it rate.
 * Configuration: ...


 * Parser_cache for the parser cache configuration used on the Wikimedia cluster
 * Manual:Object cache
 * Manual:Architectural modules/Cache
 * Manual:Configuration_settings