Help:File cache: Difference between revisions
m (1 revision(s)) |
|
(No difference)
|
Revision as of 17:30, 18 November 2006
Mediawiki supports a basic file cache for static pages for non-logged-in visitors. When an anonymous user requests a page it is constructed from the database, and also stored in the cache. When the same page is requested later on, it is directly served from the cache, without the need to query the database. This will reduce the database and server load on public sites.
Enabling the cache
The file cache is enabled by setting these variables in LocalSettings.php:
$wgUseFileCache = true; $wgFileCacheDirectory = "/tmp/yourcache"; $wgShowIPinHeader = false; $wgUseGzip = false;
Setting $wgShowIPinHeader to false is required. Since the cache serves the same page to many visitors, it's not possible to include the unique IP number of the current visitor in the page.
Setting $wgUseGzip to false is currently (1.3.0beta6) required to workaround a bug. This implies that files are cached and sent over the wire uncompressed (saves CPU cycles, at the cost of bandwith).
You need to manually create the top level cache directory and make sure Mediawiki can write to it:
mkdir -p /tmp/yourcache chmod 777 /tmp/yourcache -R
Mediawiki will automatically create a two-level directory structure in the cache directory, to improve performance of file retrieval from the cache.
You can see that the cache works by repeatedly refreshing a page with a visitor counter. Even with a forced reload (Shift-Reload in mozilla or Ctrl-Shift-Refresh in Internet Explorer) the counter will not increment.
Limitations
- It's not possible to limit or manage the size of the cache. (On Linux, see tmpwatch(8) for a good way to manage this.)
- Dynamic elements of a page (such as the visitor counter) will not be refreshed.
- Only a part of the traffic is cached. Logged-in users, special pages etc. are not cached.
Todo
- How does expiry work exactly?
- Should $wgCacheEpoch be explained?
- Point out other caching techniques (squid, Cache strategy)