Manual:Architectural modules/Cache

Responsibilities
Module cache is responsible for providing caching techniques in order to optimize the performance of MediaWiki. Both object caching and web caching are supported by MediaWiki software. Object caching stores data and single objects, that are frequently requested and require resources to be generated. There are a lot of objects that MediaWiki stores in cache, some of them are presented below:


 * User
 * ParserOutput
 * Array of data for image (version, size, width, height, metadata etc.)
 * Wiki text after xml preprocessing
 * Revision text
 * Revision differences

Web caching allows storing of entire HTML pages. To support web caching MediaWiki provides integration with the Squid proxy server and Varnish accelerator. It notifies them, when a page should be purged from the cache and regenerated.

Object Caching
Main article: Manual:Object cache.

MediaWiki supports object caching storage in many places, for example, on a file system, in the database or in an external system like memcached. The storage mode is set by the global variable in the. Additionally cache type for messages and parser can be specified by setting { {Inline-code|1=$wgParserCacheType}} and. The super class for all types of caching is, it provides interface for such methods as getting an item from cache, adding an item to cache, deleting it etc. All specific implementations of caching inherit from this class, as shown on figure Supported options for cache storing. Thus, for example, provides object caching using SQL database and  does so by using PHP's APC accelerator.

is the global variable for accessing the main cache. It is initialized from by calling. This initialization returns a specific object, for instance, in case the , it will return a. Further on whenever necessary every object can be stored by calling (providing key and value) and retrieved by calling  (providing key).

The key generation for saving in cache has some common rules. It always starts with the name of the database and follows by specification of the type of object that is being cached. Examples of such keys are shown in the table Cache keys. Final part of the key varies. For example, for user object it will be the user's id and for file object it will be the md5 hash of its name. The generation of key for ParserOutput is explained in the documentation for module Parser.

Apart from storing objects and data through 'central' caching set up by variable, MediaWiki implements itself additional types of caching. For example, or.

is used for caching of title objects and their ids, that are linked from a particular source. For example, an article would have links to other articles, used templates, categories, its talk page etc. All these links would be stored in a object and retrieved from there when needed.

implements caching of entire HTML pages on the file system. If is set to true, pages can be cached on the server and served to users when requested.

represents an object with cached contents of localization files. MediaWiki uses so called messages for any user-facing part of the interface. For instance, a message 'privacy' would have value 'Privacy policy' for English and 'Politica de proteccion de datos' for Spanish language. holds this kind of messages for loaded languages, and this way they can be easily accessed when producing the customized HTML page.

Web Caching
To provide integration with Squid or Varnish MediaWiki implements the purging notification. The class responsible for purging Squid URLs given a title (or titles) is. When an HTML page cache needs to be invalidated, an instance of is created and method  is called on it.

The overview of different types of caching in the Cache module can be seen on figure Types of cache in MediaWiki.

Parser cache
See Manual:Parser cache.