$wgMainCacheType

From Server rental store
Revision as of 03:43, 16 April 2025 by Admin (talk | contribs) (Automated server configuration article)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1. 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:

  • **Special:Statistics:** Displays various statistics, including cache hits and misses. See Special:Statistics.
  • **Server Logs:** Check your web server and cache server logs for errors or warnings.
  • **External Monitoring Tools:** Use tools like `redis-cli` (for Redis) or Memcached monitoring tools to track cache usage and performance.

Troubleshooting Cache Issues

  • **Cache Not Clearing:** Ensure the maintenance script `php maintenance/rebuildCache.php` is being run correctly. Check file permissions.
  • **Cache Server Down:** Verify your Redis or Memcached server is running and accessible.
  • **Extension Not Enabled:** Double-check that the necessary PHP extension (e.g., Redis, Memcached) is installed and enabled in your `php.ini` file. See Manual:Extensions for more information.
  • **Configuration Errors:** Carefully review your `LocalSettings.php` file for typos or incorrect settings.

Conclusion

Choosing and configuring the right `$wgMainCacheType` is a critical step in optimizing your MediaWiki installation. Redis and Memcached generally offer the best performance, but require more setup. The file cache is the simplest but least effective. Regular monitoring and troubleshooting are essential for maintaining a fast and responsive wiki. Refer to Help:Speeding up your wiki for additional optimization tips. Consider also Manual:Configuring caching for more advanced configurations.


Intel-Based Server Configurations

Configuration Specifications Benchmark
Core i7-6700K/7700 Server 64 GB DDR4, NVMe SSD 2 x 512 GB CPU Benchmark: 8046
Core i7-8700 Server 64 GB DDR4, NVMe SSD 2x1 TB CPU Benchmark: 13124
Core i9-9900K Server 128 GB DDR4, NVMe SSD 2 x 1 TB CPU Benchmark: 49969
Core i9-13900 Server (64GB) 64 GB RAM, 2x2 TB NVMe SSD
Core i9-13900 Server (128GB) 128 GB RAM, 2x2 TB NVMe SSD
Core i5-13500 Server (64GB) 64 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Server (128GB) 128 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Workstation 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000

AMD-Based Server Configurations

Configuration Specifications Benchmark
Ryzen 5 3600 Server 64 GB RAM, 2x480 GB NVMe CPU Benchmark: 17849
Ryzen 7 7700 Server 64 GB DDR5 RAM, 2x1 TB NVMe CPU Benchmark: 35224
Ryzen 9 5950X Server 128 GB RAM, 2x4 TB NVMe CPU Benchmark: 46045
Ryzen 9 7950X Server 128 GB DDR5 ECC, 2x2 TB NVMe CPU Benchmark: 63561
EPYC 7502P Server (128GB/1TB) 128 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/2TB) 128 GB RAM, 2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/4TB) 128 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/1TB) 256 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/4TB) 256 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 9454P Server 256 GB RAM, 2x2 TB NVMe

Order Your Dedicated Server

Configure and order your ideal server configuration

Need Assistance?

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