Server rental store

$wgMainCacheType

# Understanding and Configuring $wgMainCacheType

This article details the `$wgMainCacheType` configuration variable in MediaWiki 1.40. Proper configuration of this setting is crucial for optimizing performance, especially on high-traffic wikis. This guide is intended for newcomers to MediaWiki server administration.

What is `$wgMainCacheType`?

`$wgMainCacheType` defines the primary caching system used by MediaWiki to store frequently accessed data. Caching significantly reduces database load by serving pre-rendered content from faster storage, leading to quicker page loads and improved overall wiki responsiveness. Choosing the correct cache type depends on your server environment, available resources, and expected traffic. Without a suitable cache, your wiki will be slow, especially under load. See Configuration settings for a full list of settings.

Available Cache Types

MediaWiki 1.40 supports several cache types. Each has its strengths and weaknesses. Here's a breakdown of the most common options:

Cache Type Description Requirements Performance Complexity
redis A popular in-memory data structure store. Excellent performance. Redis server installed and configured. Redis extension required. Very High Medium
memcached Another widely used in-memory key-value store. Good performance. Memcached server installed and configured. Memcached extension required. High Medium
apc Alternative PHP Cache. Built-in to many PHP installations. PHP with APC extension enabled. Medium Low
eaccelerator Similar to APC, another PHP opcode cache. PHP with eAccelerator extension enabled. Medium Low
squid A reverse proxy cache. Caches entire HTTP responses. Squid proxy server installed and configured. Medium-High (depends on Squid configuration) High
file Stores cache data in files on the server. Simplest to setup. None Low Low

Configuring `$wgMainCacheType`

The `$wgMainCacheType` variable is set in your `LocalSettings.php` file. The general syntax is:

```php $wgMainCacheType = 'cache_type'; ```

Replace `'cache_type'` with the desired cache type from the table above. For example, to use Redis:

```php $wgMainCacheType = 'redis'; ```

After changing the value, you **must** clear the MediaWiki cache using the maintenance script: `php maintenance/rebuildCache.php`. See Manual:Caching for detailed information.

Specific Cache Configuration Examples

Each cache type requires additional configuration beyond simply setting `$wgMainCacheType`.

Redis Configuration

If using Redis, you'll need to configure the connection details. These are typically set using the following variables:

Variable Description Default Value
`$wgRedisHost` The hostname or IP address of the Redis server. `localhost`
`$wgRedisPort` The port number of the Redis server. `6379`
`$wgRedisPassword` The password for the Redis server (if set). (Empty string)
`$wgRedisDatabase` The Redis database number to use. `0`

Ensure the Redis extension is installed and enabled.

Memcached Configuration

For Memcached, configure the server list:

Variable Description Default Value
`$wgMemCachedServers` An array of Memcached server addresses. Format: `array('127.0.0.1:11211', '192.168.1.10:11211')` `array('127.0.0.1:11211')`

Verify the Memcached extension is installed and enabled.

File Cache Configuration

The file cache is the simplest, requiring no additional configuration beyond setting `$wgMainCacheType = 'file';`. However, it's also the least performant and is only recommended for very small wikis or testing.

Monitoring Cache Performance

It's vital to monitor your cache's performance to ensure it's functioning correctly. MediaWiki provides several tools for this:

⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️