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;
* @return bool
*/
public function isCached() {
- return file_exists( $this->cachePath() );
+ if ( $this->mCached === null ) {
+ $this->mCached = file_exists( $this->cachePath() );
+ }
+ return $this->mCached;
}
/**
$this->checkCacheDirs(); // build parent dir
if ( !file_put_contents( $this->cachePath(), $text, LOCK_EX ) ) {
+ $this->mCached = null;
return false;
}
+ $this->mCached = true;
return $text;
}
wfSuppressWarnings();
unlink( $this->cachePath() );
wfRestoreWarnings();
+ $this->mCached = false;
}
/**
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 );
}
// Get all query values
$queryVals = $context->getRequest()->getValues();
foreach ( $queryVals as $query => $val ) {
- if ( $query == 'title' || $query == 'curid' ) {
+ if ( $query === 'title' || $query === 'curid' ) {
continue; // note: curid sets title
// Normal page view in query form can have action=view.
// Raw hits for pages also stored, like .css pages for example.
- } elseif ( $query == 'action' && in_array( $val, self::cacheablePageActions() ) ) {
+ } elseif ( $query === 'action' && in_array( $val, self::cacheablePageActions() ) ) {
continue;
// Below are header setting params
- } elseif ( $query == 'maxage' || $query == 'smaxage' ) {
+ } elseif ( $query === 'maxage' || $query === 'smaxage' ) {
continue;
}
return false;
}
/**
- * Recent cache misses
+ * Item has many recent cache misses
* @return bool
*/
public function isCacheWorthy() {
if ( $this->mCacheWorthy === null ) {
- $this->mCacheWorthy = ( $this->getMissesRecent() >= self::MISS_THRESHOLD );
+ $this->mCacheWorthy = (
+ $this->isCached() || // even stale cache indicates it was cache worthy
+ $this->getMissesRecent() >= self::MISS_THRESHOLD // many misses
+ );
}
return $this->mCacheWorthy;
}