r77843 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77842‎ | r77843 | r77844 >
Date:23:07, 5 December 2010
Author:vyznev
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/HTMLFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLFileCache.php
@@ -30,7 +30,7 @@
3131
3232 public function fileCacheName() {
3333 if( !$this->mFileCache ) {
34 - global $wgCacheDirectory, $wgFileCacheDirectory;
 34+ global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth;
3535
3636 if ( $wgFileCacheDirectory ) {
3737 $dir = $wgFileCacheDirectory;
@@ -42,14 +42,17 @@
4343
4444 # Store raw pages (like CSS hits) elsewhere
4545 $subdir = ($this->mType === 'raw') ? 'raw/' : '';
 46+
4647 $key = $this->mTitle->getPrefixedDbkey();
47 - $hash = md5( $key );
 48+ if ( $wgFileCacheDepth > 0 ) {
 49+ $hash = md5( $key );
 50+ for ( $i = 1; $i < $wgFileCacheDepth; $i++ ) {
 51+ $subdir .= substr( $hash, 0, $i ) . '/';
 52+ }
 53+ }
4854 # Avoid extension confusion
4955 $key = str_replace( '.', '%2E', urlencode( $key ) );
50 -
51 - $hash1 = substr( $hash, 0, 1 );
52 - $hash2 = substr( $hash, 0, 2 );
53 - $this->mFileCache = "{$dir}/{$subdir}{$hash1}/{$hash2}/{$key}.html";
 56+ $this->mFileCache = "{$dir}/{$subdir}{$key}.html";
5457
5558 if( $this->useGzip() ) {
5659 $this->mFileCache .= '.gz';
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1602,6 +1602,14 @@
16031603 $wgFileCacheDirectory = false;
16041604
16051605 /**
 1606+ * Depth of the subdirectory hierarchy to be created under
 1607+ * $wgFileCacheDirectory. The subdirectories will be named based on
 1608+ * the MD5 hash of the title. A value of 0 means all cache files will
 1609+ * be put directly into the main file cache directory.
 1610+ */
 1611+$wgFileCacheDepth = 2;
 1612+
 1613+/**
16061614 * Keep parsed pages in a cache (objectcache table or memcached)
16071615 * to speed up output of the same page viewed by another user with the
16081616 * same options.
Index: trunk/phase3/RELEASE-NOTES
@@ -89,6 +89,8 @@
9090 * Sysops now have the "suppressredirect" right by default
9191 * (bug 22463) $wgFooterIcons added to allow configuration of the icons shown in
9292 the footers of skins.
 93+* $wgFileCacheDepth can be used to set the depth of the subdirectory hierarchy
 94+ used for the file cache. Default value is 2, which matches former behavior
9395
9496 === New features in 1.17 ===
9597 * (bug 10183) Users can now add personal styles and scripts to all skins via

Follow-up revisions

RevisionCommit summaryAuthorDate
r77846followup to r77843: fix off by one errorvyznev00:36, 6 December 2010

Comments

#Comment by Werdna (talk | contribs)   00:28, 6 December 2010

Looks OK to me.

Status & tagging log