MediaWiki is a very complex web-application, which means that it can take some time to render pages. To mitigate these costs, many MediaWiki administrators install one of many caching solutions. They are by no means compulsory, though they can decrease the time it takes pages to load, and decrease server workload. This page is divided into four sections, in order to cache everything, you need to enable a solution from each group. It is very likely that you do not need to cache everything. Simply enable things that you can, until you have acceptable performance. In some cases, over-caching will degrade performance.
PHP caching 
PHP works by compiling a PHP file into bytecode and then executing that bytecode. The process of compiling the file into bytecode takes some time. PHP accelerators work by storing the compiled bytecode and executing it directly reducing the time spent compiling code. Some PHP accelerators:
- APC (Alternative PHP cache). This is available as a package from many Linux distributions (eg Ubuntu 10.04) and PECL, and is recommended.
- PHP accelerator
- eAccelerator. Any version of eAccelerator will work for PHP caching; but, if you also want to use it for Object caching as well, you need version 0.9.5 (later versions are not compatible). Support for eAccelerator has been removed in MediaWiki 1.19.
- XCache. After Debian installation with apt-get install php5-xcache, set xcache.var_size to be >0M (e.g. 16M). Otherwise it may lead to an error.
MediaWiki does not need to be configured to do PHP caching and will "just work" if you install any of them. You can use phpinfo() to verify that the cache is installed and configured properly. More information is available from these projects.
Object caching 
When MediaWiki assembles a page to show to a user, it performs database queries to gather lots of different pieces of data and then combines it all into the page. Object caching allows MediaWiki to store these combined objects for later retrieval reducing the time spent communicating with the database and assembling pages. This is arguably the most important cache for most installations. MediaWiki can store the cached objects in a number of different places including on a file system, in the database, or in an external caching system like memcached, APC, eAccelerator, or XCache.
Since MediaWiki 1.18.0, you can define your own caching system using $wgObjectCaches.
On a single server 
$wgMainCacheType = CACHE_ACCEL;
If you are unable to use such a cache, then you may be able to use memcached, see that page for details. This is considerably more complicated, but still very effective. The other two types of object cache use a database for caching. This may (or may not) be better than nothing, but one of the previous two solutions should be tried first.
$wgMainCacheType = CACHE_DBA;
$wgMainCacheType = CACHE_DB;
If you choose CACHE_DBA, files are created in $wgTmpDirectory. This directory must be writable.
On multiple servers 
If you have multiple application servers running MediaWiki in a load-balancing configuration, you need to use memcached, detailed instructions are on that page.
Disabling caching 
$wgMainCacheType = CACHE_NONE;
Localization caching 
- New in 1.16
After finding out that a large number of the cached objects above were interface messages, the bits of text that are not content, an advanced localisation cache was introduced. Set $wgCacheDirectory in LocalSettings.php to a valid path to use.
Page caching 
Once the entire page has been rendered, it is often served multiple times, identically, to not-logged-in users. There is no need to ask MediaWiki to repeat itself.
On a single server 
You may use varnish/squid, or leverage any support your web-server has for HTTP caching. If this is not an option, for example you are on a shared host, then consider enabling the file cache, detailed instructions are on that page.
On multiple servers 
See also 
- Manual:Configuration settings#Cache
- Cache strategy
- Wikimedia servers
- PHP caching and optimization
- Manual:File cache - Optional simplistic scheme for caching the rendered HTML of article pages.
- Guide about object cache with Saetta Web Server and Mediawiki
- Manual:Varnish caching
- Manual:Squid caching
- How do I purge a cached page?
- How do I completely disable caching?
|Language:||English • Deutsch|