From abae23837d580761f2cdf67cdfffd454c69a5991 Mon Sep 17 00:00:00 2001 From: Ilmari Karonen Date: Sun, 5 Dec 2010 23:07:48 +0000 Subject: [PATCH] Add new config variable $wgFileCacheDepth to set the depth of the subdirectory hierarchy used for the file cache. Default value is 2, which matches former behavior. Setting this to 0 makes the paths simpler, and can be used with clever Apache rewrite rules to serve cached files directly without calling MediaWiki or PHP at all. --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 8 ++++++++ includes/HTMLFileCache.php | 15 +++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 7f7473deea..3fa46c5aaa 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -89,6 +89,8 @@ LocalSettings.php. The specific bugs are listed below in the general notes. * Sysops now have the "suppressredirect" right by default * (bug 22463) $wgFooterIcons added to allow configuration of the icons shown in the footers of skins. +* $wgFileCacheDepth can be used to set the depth of the subdirectory hierarchy + used for the file cache. Default value is 2, which matches former behavior === New features in 1.17 === * (bug 10183) Users can now add personal styles and scripts to all skins via diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 47db32283f..33a61017cb 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1601,6 +1601,14 @@ $wgUseFileCache = false; */ $wgFileCacheDirectory = false; +/** + * Depth of the subdirectory hierarchy to be created under + * $wgFileCacheDirectory. The subdirectories will be named based on + * the MD5 hash of the title. A value of 0 means all cache files will + * be put directly into the main file cache directory. + */ +$wgFileCacheDepth = 2; + /** * Keep parsed pages in a cache (objectcache table or memcached) * to speed up output of the same page viewed by another user with the diff --git a/includes/HTMLFileCache.php b/includes/HTMLFileCache.php index 80744f766f..e1671509e7 100644 --- a/includes/HTMLFileCache.php +++ b/includes/HTMLFileCache.php @@ -30,7 +30,7 @@ class HTMLFileCache { public function fileCacheName() { if( !$this->mFileCache ) { - global $wgCacheDirectory, $wgFileCacheDirectory; + global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth; if ( $wgFileCacheDirectory ) { $dir = $wgFileCacheDirectory; @@ -42,14 +42,17 @@ class HTMLFileCache { # Store raw pages (like CSS hits) elsewhere $subdir = ($this->mType === 'raw') ? 'raw/' : ''; + $key = $this->mTitle->getPrefixedDbkey(); - $hash = md5( $key ); + if ( $wgFileCacheDepth > 0 ) { + $hash = md5( $key ); + for ( $i = 1; $i < $wgFileCacheDepth; $i++ ) { + $subdir .= substr( $hash, 0, $i ) . '/'; + } + } # Avoid extension confusion $key = str_replace( '.', '%2E', urlencode( $key ) ); - - $hash1 = substr( $hash, 0, 1 ); - $hash2 = substr( $hash, 0, 2 ); - $this->mFileCache = "{$dir}/{$subdir}{$hash1}/{$hash2}/{$key}.html"; + $this->mFileCache = "{$dir}/{$subdir}{$key}.html"; if( $this->useGzip() ) { $this->mFileCache .= '.gz'; -- 2.20.1