手册:$wgMainCacheType
| 缓存: $wgMainCacheType | |
|---|---|
| 对象缓存设置 |
|
| 引进版本: | 1.5.0 |
| 移除版本: | 仍在使用 |
| 允许的值: | (CACHE常量之一(见下文),或指示缓存类型的字符串,设置为$wgObjectCaches中的键) |
| 默认值: | CACHE_NONE |
| 其他设置: 按首字母排序 | 按功能排序 | |
细节
允许配置使用的对象缓存。
以下是默认情况下可用的键(在Definition.php中定义为常量):
CACHE_NONE– 不使用缓存(默认)。CACHE_ANYTHING– 如果$wgMessageCacheType或$wgParserCacheType不是CACHE_NONE或CACHE_ANYTHING,将使用它们的值。 否则,将使用CACHE_DB。CACHE_ACCEL– 如果已安装并配置APCu或OPcache,则会优先使用。 (maintenance/install.php 将会添加$wgMainCacheType = CACHE_ACCEL;到你的配置文件中)CACHE_MEMCACHED– 如果可用,将使用memcached。必须在$wgMemCachedServers中另外指定服务器。CACHE_DB– 使用数据库表objectcache。
- 警告: 这可能比没有缓存要慢,即
CACHE_NONE。
PHP的工作原理是将PHP文件编译为字节码,然后执行该字节码。 编译大型应用程序(如MediaWiki)的过程需要相当长的时间。 PHP加速器通过存储编译后的字节码并直接执行它来减少编译代码所花费的时间。
OPcache包含在PHP 5.5.0及更高版本中,是MediaWiki的推荐加速器。
字节码缓存将会存储PHP脚本的编译结果,显著地减少了重复运行脚本所需的时间。 MediaWiki不需要特别配置来执行PHP字节码缓存,一旦安装并启用它们就会“正常工作”。
有关自定义缓存后端(例如Redis)的示例,请参阅$wgObjectCaches。
- 有人指出,在安装了memcached和字节码缓存的情况下,
CACHE_MEMCACHED指令将提供最显著的性能提升。 - 这只是MediaWiki的缓存设置之一。 为了获得最佳性能表现,您可能需要考虑设置其他类型的缓存。 请参阅performance tuning。
- 自MediaWiki 1.27以来,PHP会话存储在缓存中,这取决于此设置的变量,除非被$wgSessionCacheType覆盖。 如果apcu配置错误,使用
CACHE_ACCEL时可能会出现问题 (see T147161).
Login session problem with APCu in a multi process or multi server environment
$wgSessionCacheType inherits $wgMainCacheType unless configured otherwise.
Selecting CACHE_ACCEL as the cache type can cause inconsistent behavior where session data is lost, and the user must log back in. This is because php-fpm processes can be ephemeral or not good at talking to each other. There can also be problems in a multi-server environment.
The workaround is to use the database to store these sessions. Add the following line to LocalSettings.php
$wgSessionCacheType = CACHE_DB;