From: Aaron Schulz Date: Sun, 28 Dec 2008 14:19:39 +0000 (+0000) Subject: FileCache cleanuo: X-Git-Tag: 1.31.0-rc.0~43724 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=f0a60c4fef7d5571cf45512f366a9bb218f44277;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/Article.php b/includes/Article.php index 1b4bcce954..b0bf080da4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -3164,7 +3164,7 @@ class Article { } public static function onArticleDelete( $title ) { - global $wgUseFileCache, $wgMessageCache; + global $wgMessageCache; # Update existence markers on article/talk tabs... if( $title->isTalkPage() ) { $other = $title->getSubjectPage(); @@ -3178,10 +3178,7 @@ class Article { $title->purgeSquid(); # File cache - if( $wgUseFileCache ) { - $cm = new HTMLFileCache( $title ); - @unlink( $cm->fileCacheName() ); - } + HTMLFileCache::clearFileCache( $title ); # Messages if( $title->getNamespace() == NS_MEDIAWIKI ) { @@ -3203,7 +3200,7 @@ class Article { * Purge caches on page update etc */ public static function onArticleEdit( $title, $transclusions = 'transclusions' ) { - global $wgDeferredUpdateList, $wgUseFileCache; + global $wgDeferredUpdateList; // Invalidate caches of articles which include this page if( $transclusions !== 'skiptransclusions' ) @@ -3216,10 +3213,7 @@ class Article { $title->purgeSquid(); # Clear file cache for this page only - if( $wgUseFileCache ) { - $cm = new HTMLFileCache( $title ); - @unlink( $cm->fileCacheName() ); - } + HTMLFileCache::clearFileCache( $title ); } /**#@-*/ diff --git a/includes/HTMLCacheUpdate.php b/includes/HTMLCacheUpdate.php index 636d73f045..402102ea41 100644 --- a/includes/HTMLCacheUpdate.php +++ b/includes/HTMLCacheUpdate.php @@ -172,8 +172,7 @@ class HTMLCacheUpdate # Update file cache if ( $wgUseFileCache ) { foreach ( $titles as $title ) { - $cm = new HTMLFileCache($title); - @unlink($cm->fileCacheName()); + HTMLFileCache::clearFileCache( $title ); } } } diff --git a/includes/HTMLFileCache.php b/includes/HTMLFileCache.php index 15037cc6f7..3f27d448ac 100644 --- a/includes/HTMLFileCache.php +++ b/includes/HTMLFileCache.php @@ -20,22 +20,23 @@ * @ingroup Cache */ class HTMLFileCache { - var $mTitle, $mFileCache; + var $mTitle, $mFileCache, $mType; - public function __construct( &$title ) { + public function __construct( &$title, $type = 'view' ) { $this->mTitle = $title; - $this->mFileCache = $this->fileCacheName(); + $this->mType = ($type == 'raw' || $type == 'view' ) ? $type : false; + $this->fileCacheName(); // init name } public function fileCacheName() { if( !$this->mFileCache ) { global $wgFileCacheDirectory, $wgRequest; + # Store raw pages (like CSS hits) elsewhere + $subdir = ($this->mType === 'raw') ? 'raw/' : ''; $key = $this->mTitle->getPrefixedDbkey(); $hash = md5( $key ); # Avoid extension confusion $key = str_replace( '.', '%2E', urlencode( $key ) ); - # Store raw pages (like CSS hits) elsewhere - $subdir = $wgRequest->getVal('action') == 'raw' ? 'raw/' : ''; $hash1 = substr( $hash, 0, 1 ); $hash2 = substr( $hash, 0, 2 ); @@ -50,6 +51,7 @@ class HTMLFileCache { } public function isFileCached() { + if( $this->mType === false ) return false; return file_exists( $this->fileCacheName() ); } @@ -70,11 +72,13 @@ class HTMLFileCache { if( $query == 'title' || $query == 'curid' ) continue; // Normal page view in query form can have action=view. // Raw hits for pages also stored, like .css pages for example. - if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue; - if( $query == 'usemsgcache' && $val == 'yes' ) continue; + else if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue; + else if( $query == 'usemsgcache' && $val == 'yes' ) continue; // Below are header setting params - if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) + else if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) continue; + else + return false; } // Check for non-standard user language; this covers uselang, // and extensions for auto-detecting user language. @@ -193,4 +197,13 @@ class HTMLFileCache { return $text; } + public static function clearFileCache( $title ) { + global $wgUseFileCache; + if( !$wgUseFileCache ) return false; + $fc = new self( $title, '' ); + @unlink( $fc->fileCacheName() ); + $fc = new self( $title, 'raw' ); + @unlink( $fc->fileCacheName() ); + return true; + } } diff --git a/includes/RawPage.php b/includes/RawPage.php index 9640cee904..a7bc02c14c 100644 --- a/includes/RawPage.php +++ b/includes/RawPage.php @@ -151,7 +151,7 @@ class RawPage { header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage ); if( HTMLFileCache::useFileCache() ) { - $cache = new HTMLFileCache( $this->mTitle ); + $cache = new HTMLFileCache( $this->mTitle, 'raw' ); if( $cache->isFileCacheGood( /* Assume up to date */ ) ) { /* Check incoming headers to see if client has this cached */ if( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) { diff --git a/includes/Title.php b/includes/Title.php index abfae90847..033d045d00 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1954,7 +1954,6 @@ class Title { * @return \type{\bool} true if the update succeded */ public function invalidateCache() { - global $wgUseFileCache; if( wfReadOnly() ) { return; } @@ -1964,10 +1963,7 @@ class Title { $this->pageCond(), __METHOD__ ); - if( $wgUseFileCache) { - $cache = new HTMLFileCache( $this ); - @unlink( $cache->fileCacheName() ); - } + HTMLFileCache::clearFileCache( $this ); return $success; }