Server rental store

Caching Strategies

# Caching Strategies for MediaWiki 1.40

This article details various caching strategies employed to optimize the performance of a MediaWiki 1.40 installation. Efficient caching is crucial for handling high traffic and reducing server load. This guide is aimed at newcomers to server administration of MediaWiki sites.

Understanding Caching in MediaWiki

Caching, in the context of MediaWiki, involves storing frequently accessed data in a temporary storage location (the “cache”) so that future requests for that data can be served faster. Without caching, the server would need to regenerate the requested content for every single request, which can be resource-intensive. MediaWiki utilizes several layers of caching, each addressing different aspects of performance. We will cover the most important ones. See Configuration settings for a full list of configurable settings.

1. Parser Cache

The parser cache stores the output of the parser after it has processed a page. This is arguably the most significant cache for performance. When a user requests a page, MediaWiki first checks if a recent version of the parsed output is available in the parser cache. If so, it serves the cached version, bypassing the potentially expensive parsing process.

Technical Specifications:

Parameter Description Default Value Recommended Value
`$wgParserCacheType` Specifies the type of parser cache to use. 'redis' 'redis' (highly recommended)
`$wgParserCacheTTL` Time-to-live (TTL) for parser cache entries, in seconds. 3600 (1 hour) 86400 (24 hours) - adjust based on update frequency.
`$wgCachePages` Enables or disables caching of pages. true true

Consider using a robust caching backend like Redis or Memcached for the parser cache. The default file-based cache is suitable for very small sites only. See Caching for more details.

2. Output Cache

The output cache stores the complete HTML output of a page after it has been rendered. This includes the parsed content, the site’s styling and layout, and any other dynamic elements. The output cache is checked *after* the parser cache. If a cached version exists, it is delivered directly to the user.

Technical Specifications:

Parameter Description Default Value Recommended Value
`$wgMainCacheType` Specifies the type of output cache to use. 'redis' 'redis' (highly recommended)
`$wgUseCommaForEffectMarker` Determines how effects are marked for output caching. true true
`$wgCacheDirectory` Directory where the output cache is stored (if using file-based caching). $wgUploadDirectory . '/cache' N/A (if using Redis or Memcached)

3. Database Caching

MediaWiki frequently queries the database. Database caching reduces the load on the database server by storing the results of common queries. This is often handled by the underlying database system itself (e.g., MySQL's query cache), but MediaWiki also provides some additional database caching mechanisms.

Technical Specifications:

Parameter Description Default Value Recommended Value
`$wgDBcacheSearch` Enables caching of search results. false true (if search is heavily used)
`$wgDBcacheTransforms` Enables caching of transform results (e.g., title normalization). false true
`$wgDBcacheExpiry` Expiry time for database cache entries, in seconds. 3600 (1 hour) 86400 (24 hours)

Consider optimizing your database queries through proper indexing and careful schema design. See Database access for more information.

4. Other Caching Mechanisms

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