Manual:$wgFileCacheDepth/ja

詳細
This variable controls the depth of the subdirectory hierarchy created under $wgFileCacheDirectory to store cached pages when $wgUseFileCache = true;.

By default, two levels of intermediate directories are created, matching the behavior in MediaWiki 1.16 and earlier. The directories are named using prefixes of the hexadecimal MD5 hash of the page title. For example, if the title of the page was "Example" (which has the MD5 hash "0a52730597fb4ffa01fc117d9e71e3a9"), the file in which the cached page was stored would be named


 * $wgFileCacheDirectory/0/0a/Example.html

The purpose of the subdirectory hierarchy is to spread the cached files evenly around several directories, thereby reducing the number of files in each individual directory. On some file systems, this can improve performance if the number of cached pages is large. However, if your wiki is small, or if you know your file system can handle huge directories efficiently, you might want to set $wgFileCacheDepth = 0; to get rid of the intermediate directories entirely. (Conversely, if your wiki is huge, you could try increasing the value to spread the files over even more directories.)

Serving cached pages directly
Setting $wgFileCacheDepth = 0; also makes it considerably easier to use webserver configuration tricks to serve cached files directly without invoking MediaWiki or PHP at all.

For example, the following mod_rewrite rule has been found to work in an .htaccess file on a shared webhost running Apache 2.2:

RewriteBase / RewriteCond %{HTTP_COOKIE} !UserID= RewriteCond %{QUERY_STRING} !. RewriteCond %{DOCUMENT_ROOT}/w/html_cache/$1.html -s RewriteRule ^wiki/(.+)$ /w/html_cache/$1.html [B,L,NS]
 * 1) If a cached page exists under /w/html_cache, do an internal redirect to it:

However, this rewrite rule won't work properly for pages whose titles contain punctuation or non-ASCII characters. A tidy solution would be to use a RewriteMap, but this is not supported in .htaccess context. Instead, the following trick can be used to handle non-ASCII titles by pulling the URL-escaped title directly from the raw request line:

RewriteBase / RewriteCond %{HTTP_COOKIE} !UserID= RewriteCond %{QUERY_STRING} !. ReWriteCond %{THE_REQUEST} ^GET\x20/wiki/([^\x20/]+)\x20HTTP RewriteCond %{DOCUMENT_ROOT}/w/html_cache/%1.html -s RewriteRule ^wiki/(.+)$ /w/html_cache/%1.html [B,L,NS]
 * 1) If a cached page exists under /w/html_cache, do an internal redirect to it:

This will still not match titles containing periods, slashes or other punctuation which the file cache escapes but browsers don't (or vice versa). One should also ensure that the appropriate Vary header gets sent:

Header append Vary Cookie

Also note that, since this redirect trick bypasses MediaWiki entirely, it won't respect $wgCacheEpoch. You may need to clear or rebuild the cache manually as needed instead.

(If you know better ways to achieve this, please add them here. Thank you.)

関連項目

 * File cache