r98705 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98704‎ | r98705 | r98706 >
Date:19:44, 2 October 2011
Author:aaron
Status:ok
Tags:
Comment:
* Added isCacheWorthy() optimization (checks if the file exists, stale or not)
* Made isCached() use process cache
* Added MISS_TTL_SEC constant and tweaked MISS_FACTOR constant
Modified paths:
  • /trunk/phase3/includes/cache/FileCacheBase.php (modified) (history)
  • /trunk/phase3/includes/cache/HTMLFileCache.php (modified) (history)
  • /trunk/phase3/includes/cache/ResourceFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/cache/ResourceFileCache.php
@@ -72,12 +72,15 @@
7373 }
7474
7575 /**
76 - * Recent cache misses
 76+ * Item has many recent cache misses
7777 * @return bool
7878 */
7979 public function isCacheWorthy() {
8080 if ( $this->mCacheWorthy === null ) {
81 - $this->mCacheWorthy = ( $this->getMissesRecent() >= self::MISS_THRESHOLD );
 81+ $this->mCacheWorthy = (
 82+ $this->isCached() || // even stale cache indicates it was cache worthy
 83+ $this->getMissesRecent() >= self::MISS_THRESHOLD // many misses
 84+ );
8285 }
8386 return $this->mCacheWorthy;
8487 }
Index: trunk/phase3/includes/cache/FileCacheBase.php
@@ -10,9 +10,12 @@
1111 protected $mExt = 'cache';
1212 protected $mFilePath;
1313 protected $mUseGzip;
 14+ /* lazy loaded */
 15+ protected $mCached;
1416
1517 /* @TODO: configurable? */
16 - const MISS_FACTOR = 10; // log 1 every MISS_FACTOR cache misses
 18+ const MISS_FACTOR = 15; // log 1 every MISS_FACTOR cache misses
 19+ const MISS_TTL_SEC = 3600; // how many seconds ago is "recent"
1720
1821 protected function __construct() {
1922 global $wgUseGzip;
@@ -70,7 +73,10 @@
7174 * @return bool
7275 */
7376 public function isCached() {
74 - return file_exists( $this->cachePath() );
 77+ if ( $this->mCached === null ) {
 78+ $this->mCached = file_exists( $this->cachePath() );
 79+ }
 80+ return $this->mCached;
7581 }
7682
7783 /**
@@ -142,9 +148,11 @@
143149
144150 $this->checkCacheDirs(); // build parent dir
145151 if ( !file_put_contents( $this->cachePath(), $text, LOCK_EX ) ) {
 152+ $this->mCached = null;
146153 return false;
147154 }
148155
 156+ $this->mCached = true;
149157 return $text;
150158 }
151159
@@ -156,6 +164,7 @@
157165 wfSuppressWarnings();
158166 unlink( $this->cachePath() );
159167 wfRestoreWarnings();
 168+ $this->mCached = false;
160169 }
161170
162171 /**
@@ -216,12 +225,12 @@
217226 if ( $wgMemc->get( $key ) ) {
218227 return; // possibly the same user
219228 }
220 - $wgMemc->set( $key, 1, 3600 );
 229+ $wgMemc->set( $key, 1, self::MISS_TTL_SEC );
221230
222231 # Increment the number of cache misses...
223232 $key = $this->cacheMissKey();
224233 if ( $wgMemc->get( $key ) === false ) {
225 - $wgMemc->set( $key, 1, 3600 );
 234+ $wgMemc->set( $key, 1, self::MISS_TTL_SEC );
226235 } else {
227236 $wgMemc->incr( $key );
228237 }
Index: trunk/phase3/includes/cache/HTMLFileCache.php
@@ -75,14 +75,14 @@
7676 // Get all query values
7777 $queryVals = $context->getRequest()->getValues();
7878 foreach ( $queryVals as $query => $val ) {
79 - if ( $query == 'title' || $query == 'curid' ) {
 79+ if ( $query === 'title' || $query === 'curid' ) {
8080 continue; // note: curid sets title
8181 // Normal page view in query form can have action=view.
8282 // Raw hits for pages also stored, like .css pages for example.
83 - } elseif ( $query == 'action' && in_array( $val, self::cacheablePageActions() ) ) {
 83+ } elseif ( $query === 'action' && in_array( $val, self::cacheablePageActions() ) ) {
8484 continue;
8585 // Below are header setting params
86 - } elseif ( $query == 'maxage' || $query == 'smaxage' ) {
 86+ } elseif ( $query === 'maxage' || $query === 'smaxage' ) {
8787 continue;
8888 }
8989 return false;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98698FileCache:...aaron17:53, 2 October 2011

Status & tagging log