Manual:Cache/ru

MediaWiki — это комплексное веб-приложение, которое требует много ресурсов для рендера. Для решения этой проблемы некоторые администраторы используют кэширование, что позволяет тратить меньше ресурсов сервера, не заставляя его заново создавать страницу, которая уже была создана однажды.

Эта страница расскажет о четырёх решениях кэширования.

Обычно мы рекомендуем использовать APC и memcached, как это делают крупные проекты типа Русской и Английской Википедий. Performance tuning.

PHP кэш
PHP преобразует php-код в байткод, с последующим его выплнением. Такой процесс занимает достаточно много времени. PHP акселераторы хранят интерпретированный байт-код и выполняют его за гораздо более короткий срок. Вот некоторые из них:


 * APC (Alternative PHP cache). Это пакет для Linux-дистрибутивов (см. Manual:APC);
 * PHP accelerator;
 * XCache.

MediaWiki вообще не нужно специально настраивать для этого, она «просто работает», если у вас есть один из акселераторов. Запустите phpinfo, чтобы убедиться, что акселератор установлен и работает.

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
If you have a PHP byte-code cache, see PHP caching above, you can easily use this to store all of the extra data. This is strongly recommended, and requires the following line in LocalSettings.php:

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.

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.

If you set $wgMainCacheType then the values for $wgParserCacheType and $wgMessageCacheType will inherit it. You do not need to set those variables unless you plan on doing something very advanced.

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. It uses the database l10n cache table by default. Set $wgCacheDirectory in LocalSettings.php to a valid path to use a local caching instead. See Localisation for more details.

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
If you have multiple application servers running MediaWiki in a load-balanced configuration, use an existing HTTP-level cache, such as varnish or squid.