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 main ParserCache stores output of the latest revision of a page.

Metadata and Payload Data

 * 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.

Cache Structure and Key Space
The ParserCache supports storing multiple  objects for each page, based on the   used when generating the output. To avoid duplicating cache entries by varying the cache key on options that were not actually used, a two-tiered system is employed:

The first tier is keyed by the page ID and stores, which contains information about cache expiration and the list of   used during the parse of the page. For example, if only the dateformat and userlang options were accessed by the parser when producing output for the page, this fact will be stored in the metadata cache.

The second tier of the cache contains the actual  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 the first tier, 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 the dateformat and userlang options affected the output for the page, the key will look like. Thus any cache lookup with  and   will hit the same cache entry regardless of the values of the rest of the options, since we know from the information in the first cache tier that they were not accessed during a parse and thus did not change the output.

Population, Invalidation, Expiry, and Eviction

 * 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.

ParserCache Factory

 * 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.

Old Revision Output Cache

 * 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
See Manual:Configuration_settings