| Index: trunk/phase3/includes/cache/ResourceFileCache.php |
| — | — | @@ -72,12 +72,15 @@ |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | | - * Recent cache misses |
| | 76 | + * Item has many recent cache misses |
| 77 | 77 | * @return bool |
| 78 | 78 | */ |
| 79 | 79 | public function isCacheWorthy() { |
| 80 | 80 | 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 | + ); |
| 82 | 85 | } |
| 83 | 86 | return $this->mCacheWorthy; |
| 84 | 87 | } |
| Index: trunk/phase3/includes/cache/FileCacheBase.php |
| — | — | @@ -10,9 +10,12 @@ |
| 11 | 11 | protected $mExt = 'cache'; |
| 12 | 12 | protected $mFilePath; |
| 13 | 13 | protected $mUseGzip; |
| | 14 | + /* lazy loaded */ |
| | 15 | + protected $mCached; |
| 14 | 16 | |
| 15 | 17 | /* @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" |
| 17 | 20 | |
| 18 | 21 | protected function __construct() { |
| 19 | 22 | global $wgUseGzip; |
| — | — | @@ -70,7 +73,10 @@ |
| 71 | 74 | * @return bool |
| 72 | 75 | */ |
| 73 | 76 | 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; |
| 75 | 81 | } |
| 76 | 82 | |
| 77 | 83 | /** |
| — | — | @@ -142,9 +148,11 @@ |
| 143 | 149 | |
| 144 | 150 | $this->checkCacheDirs(); // build parent dir |
| 145 | 151 | if ( !file_put_contents( $this->cachePath(), $text, LOCK_EX ) ) { |
| | 152 | + $this->mCached = null; |
| 146 | 153 | return false; |
| 147 | 154 | } |
| 148 | 155 | |
| | 156 | + $this->mCached = true; |
| 149 | 157 | return $text; |
| 150 | 158 | } |
| 151 | 159 | |
| — | — | @@ -156,6 +164,7 @@ |
| 157 | 165 | wfSuppressWarnings(); |
| 158 | 166 | unlink( $this->cachePath() ); |
| 159 | 167 | wfRestoreWarnings(); |
| | 168 | + $this->mCached = false; |
| 160 | 169 | } |
| 161 | 170 | |
| 162 | 171 | /** |
| — | — | @@ -216,12 +225,12 @@ |
| 217 | 226 | if ( $wgMemc->get( $key ) ) { |
| 218 | 227 | return; // possibly the same user |
| 219 | 228 | } |
| 220 | | - $wgMemc->set( $key, 1, 3600 ); |
| | 229 | + $wgMemc->set( $key, 1, self::MISS_TTL_SEC ); |
| 221 | 230 | |
| 222 | 231 | # Increment the number of cache misses... |
| 223 | 232 | $key = $this->cacheMissKey(); |
| 224 | 233 | if ( $wgMemc->get( $key ) === false ) { |
| 225 | | - $wgMemc->set( $key, 1, 3600 ); |
| | 234 | + $wgMemc->set( $key, 1, self::MISS_TTL_SEC ); |
| 226 | 235 | } else { |
| 227 | 236 | $wgMemc->incr( $key ); |
| 228 | 237 | } |
| Index: trunk/phase3/includes/cache/HTMLFileCache.php |
| — | — | @@ -75,14 +75,14 @@ |
| 76 | 76 | // Get all query values |
| 77 | 77 | $queryVals = $context->getRequest()->getValues(); |
| 78 | 78 | foreach ( $queryVals as $query => $val ) { |
| 79 | | - if ( $query == 'title' || $query == 'curid' ) { |
| | 79 | + if ( $query === 'title' || $query === 'curid' ) { |
| 80 | 80 | continue; // note: curid sets title |
| 81 | 81 | // Normal page view in query form can have action=view. |
| 82 | 82 | // 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() ) ) { |
| 84 | 84 | continue; |
| 85 | 85 | // Below are header setting params |
| 86 | | - } elseif ( $query == 'maxage' || $query == 'smaxage' ) { |
| | 86 | + } elseif ( $query === 'maxage' || $query === 'smaxage' ) { |
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | 89 | return false; |