r45124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45123‎ | r45124 | r45125 >
Date:14:19, 28 December 2008
Author:aaron
Status:ok
Tags:
Comment:
FileCache cleanuo:
* Add a clearFileCache() function in the place of various unlink() calls. This also clears the raw page cache.
* Fix useFileCache() for loop
* Add mType field to file cache objects
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/HTMLCacheUpdate.php (modified) (history)
  • /trunk/phase3/includes/HTMLFileCache.php (modified) (history)
  • /trunk/phase3/includes/RawPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -3164,7 +3164,7 @@
31653165 }
31663166
31673167 public static function onArticleDelete( $title ) {
3168 - global $wgUseFileCache, $wgMessageCache;
 3168+ global $wgMessageCache;
31693169 # Update existence markers on article/talk tabs...
31703170 if( $title->isTalkPage() ) {
31713171 $other = $title->getSubjectPage();
@@ -3178,10 +3178,7 @@
31793179 $title->purgeSquid();
31803180
31813181 # File cache
3182 - if( $wgUseFileCache ) {
3183 - $cm = new HTMLFileCache( $title );
3184 - @unlink( $cm->fileCacheName() );
3185 - }
 3182+ HTMLFileCache::clearFileCache( $title );
31863183
31873184 # Messages
31883185 if( $title->getNamespace() == NS_MEDIAWIKI ) {
@@ -3203,7 +3200,7 @@
32043201 * Purge caches on page update etc
32053202 */
32063203 public static function onArticleEdit( $title, $transclusions = 'transclusions' ) {
3207 - global $wgDeferredUpdateList, $wgUseFileCache;
 3204+ global $wgDeferredUpdateList;
32083205
32093206 // Invalidate caches of articles which include this page
32103207 if( $transclusions !== 'skiptransclusions' )
@@ -3216,10 +3213,7 @@
32173214 $title->purgeSquid();
32183215
32193216 # Clear file cache for this page only
3220 - if( $wgUseFileCache ) {
3221 - $cm = new HTMLFileCache( $title );
3222 - @unlink( $cm->fileCacheName() );
3223 - }
 3217+ HTMLFileCache::clearFileCache( $title );
32243218 }
32253219
32263220 /**#@-*/
Index: trunk/phase3/includes/Title.php
@@ -1954,7 +1954,6 @@
19551955 * @return \type{\bool} true if the update succeded
19561956 */
19571957 public function invalidateCache() {
1958 - global $wgUseFileCache;
19591958 if( wfReadOnly() ) {
19601959 return;
19611960 }
@@ -1964,10 +1963,7 @@
19651964 $this->pageCond(),
19661965 __METHOD__
19671966 );
1968 - if( $wgUseFileCache) {
1969 - $cache = new HTMLFileCache( $this );
1970 - @unlink( $cache->fileCacheName() );
1971 - }
 1967+ HTMLFileCache::clearFileCache( $this );
19721968 return $success;
19731969 }
19741970
Index: trunk/phase3/includes/RawPage.php
@@ -151,7 +151,7 @@
152152 header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
153153
154154 if( HTMLFileCache::useFileCache() ) {
155 - $cache = new HTMLFileCache( $this->mTitle );
 155+ $cache = new HTMLFileCache( $this->mTitle, 'raw' );
156156 if( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
157157 /* Check incoming headers to see if client has this cached */
158158 if( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) {
Index: trunk/phase3/includes/HTMLFileCache.php
@@ -20,22 +20,23 @@
2121 * @ingroup Cache
2222 */
2323 class HTMLFileCache {
24 - var $mTitle, $mFileCache;
 24+ var $mTitle, $mFileCache, $mType;
2525
26 - public function __construct( &$title ) {
 26+ public function __construct( &$title, $type = 'view' ) {
2727 $this->mTitle = $title;
28 - $this->mFileCache = $this->fileCacheName();
 28+ $this->mType = ($type == 'raw' || $type == 'view' ) ? $type : false;
 29+ $this->fileCacheName(); // init name
2930 }
3031
3132 public function fileCacheName() {
3233 if( !$this->mFileCache ) {
3334 global $wgFileCacheDirectory, $wgRequest;
 35+ # Store raw pages (like CSS hits) elsewhere
 36+ $subdir = ($this->mType === 'raw') ? 'raw/' : '';
3437 $key = $this->mTitle->getPrefixedDbkey();
3538 $hash = md5( $key );
3639 # Avoid extension confusion
3740 $key = str_replace( '.', '%2E', urlencode( $key ) );
38 - # Store raw pages (like CSS hits) elsewhere
39 - $subdir = $wgRequest->getVal('action') == 'raw' ? 'raw/' : '';
4041
4142 $hash1 = substr( $hash, 0, 1 );
4243 $hash2 = substr( $hash, 0, 2 );
@@ -50,6 +51,7 @@
5152 }
5253
5354 public function isFileCached() {
 55+ if( $this->mType === false ) return false;
5456 return file_exists( $this->fileCacheName() );
5557 }
5658
@@ -70,11 +72,13 @@
7173 if( $query == 'title' || $query == 'curid' ) continue;
7274 // Normal page view in query form can have action=view.
7375 // Raw hits for pages also stored, like .css pages for example.
74 - if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue;
75 - if( $query == 'usemsgcache' && $val == 'yes' ) continue;
 76+ else if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue;
 77+ else if( $query == 'usemsgcache' && $val == 'yes' ) continue;
7678 // Below are header setting params
77 - if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' )
 79+ else if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' )
7880 continue;
 81+ else
 82+ return false;
7983 }
8084 // Check for non-standard user language; this covers uselang,
8185 // and extensions for auto-detecting user language.
@@ -193,4 +197,13 @@
194198 return $text;
195199 }
196200
 201+ public static function clearFileCache( $title ) {
 202+ global $wgUseFileCache;
 203+ if( !$wgUseFileCache ) return false;
 204+ $fc = new self( $title, '' );
 205+ @unlink( $fc->fileCacheName() );
 206+ $fc = new self( $title, 'raw' );
 207+ @unlink( $fc->fileCacheName() );
 208+ return true;
 209+ }
197210 }
Index: trunk/phase3/includes/HTMLCacheUpdate.php
@@ -172,8 +172,7 @@
173173 # Update file cache
174174 if ( $wgUseFileCache ) {
175175 foreach ( $titles as $title ) {
176 - $cm = new HTMLFileCache($title);
177 - @unlink($cm->fileCacheName());
 176+ HTMLFileCache::clearFileCache( $title );
178177 }
179178 }
180179 }

Status & tagging log