diff options
author | Aaron Schulz <aaron@users.mediawiki.org> | 2011-10-02 19:44:31 +0000 |
---|---|---|
committer | Aaron Schulz <aaron@users.mediawiki.org> | 2011-10-02 19:44:31 +0000 |
commit | 1ba93d9b77b06daba56b21ed4af13eff9c2beb8e (patch) | |
tree | 934ba0c5a0aef321fe67339ad201aa15138654a8 /includes/cache/FileCacheBase.php | |
parent | 5d5601cb797d049e8f4fefe154d119bf381becfc (diff) | |
download | mediawikicore-1ba93d9b77b06daba56b21ed4af13eff9c2beb8e.tar.gz mediawikicore-1ba93d9b77b06daba56b21ed4af13eff9c2beb8e.zip |
* 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
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/98705
Diffstat (limited to 'includes/cache/FileCacheBase.php')
-rw-r--r-- | includes/cache/FileCacheBase.php | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/includes/cache/FileCacheBase.php b/includes/cache/FileCacheBase.php index 1ed9546f9346..e6be04933527 100644 --- a/includes/cache/FileCacheBase.php +++ b/includes/cache/FileCacheBase.php @@ -10,9 +10,12 @@ abstract class FileCacheBase { protected $mExt = 'cache'; protected $mFilePath; protected $mUseGzip; + /* lazy loaded */ + protected $mCached; /* @TODO: configurable? */ - const MISS_FACTOR = 10; // log 1 every MISS_FACTOR cache misses + const MISS_FACTOR = 15; // log 1 every MISS_FACTOR cache misses + const MISS_TTL_SEC = 3600; // how many seconds ago is "recent" protected function __construct() { global $wgUseGzip; @@ -70,7 +73,10 @@ abstract class FileCacheBase { * @return bool */ public function isCached() { - return file_exists( $this->cachePath() ); + if ( $this->mCached === null ) { + $this->mCached = file_exists( $this->cachePath() ); + } + return $this->mCached; } /** @@ -142,9 +148,11 @@ abstract class FileCacheBase { $this->checkCacheDirs(); // build parent dir if ( !file_put_contents( $this->cachePath(), $text, LOCK_EX ) ) { + $this->mCached = null; return false; } + $this->mCached = true; return $text; } @@ -156,6 +164,7 @@ abstract class FileCacheBase { wfSuppressWarnings(); unlink( $this->cachePath() ); wfRestoreWarnings(); + $this->mCached = false; } /** @@ -216,12 +225,12 @@ abstract class FileCacheBase { if ( $wgMemc->get( $key ) ) { return; // possibly the same user } - $wgMemc->set( $key, 1, 3600 ); + $wgMemc->set( $key, 1, self::MISS_TTL_SEC ); # Increment the number of cache misses... $key = $this->cacheMissKey(); if ( $wgMemc->get( $key ) === false ) { - $wgMemc->set( $key, 1, 3600 ); + $wgMemc->set( $key, 1, self::MISS_TTL_SEC ); } else { $wgMemc->incr( $key ); } |