$paths = array_merge( $paths, $op->storagePathsRead() );
$paths = array_merge( $paths, $op->storagePathsChanged() );
}
+
+ // Enlarge the cache to fit the stat entries of these files
+ $this->cheapCache->resize( max( 2 * count( $paths ), self::CACHE_CHEAP_SIZE ) );
+
// Load from the persistent container caches
$this->primeContainerCache( $paths );
// Get the latest stat info for all the files (having locked them)
$status->merge( $subStatus );
$status->success = $subStatus->success; // not done in merge()
+ // Shrink the stat cache back to normal size
+ $this->cheapCache->resize( self::CACHE_CHEAP_SIZE );
+
return $status;
}
* @throws UnexpectedValueException When $maxCacheKeys is not an int or =< 0.
*/
public function __construct( $maxKeys ) {
- if ( !is_int( $maxKeys ) || $maxKeys < 1 ) {
- throw new UnexpectedValueException( __METHOD__ . " must be given an integer >= 1" );
- }
- $this->maxCacheKeys = $maxKeys;
+ $this->resize( $maxKeys );
}
/**
}
}
+ /**
+ * Resize the maximum number of cache entries, removing older entries as needed
+ *
+ * @param $maxKeys integer
+ * @return void
+ */
+ public function resize( $maxKeys ) {
+ if ( !is_int( $maxKeys ) || $maxKeys < 1 ) {
+ throw new UnexpectedValueException( __METHOD__ . " must be given an integer >= 1" );
+ }
+ $this->maxCacheKeys = $maxKeys;
+ while ( count( $this->cache ) > $this->maxCacheKeys ) {
+ reset( $this->cache );
+ $evictKey = key( $this->cache );
+ unset( $this->cache[$evictKey] );
+ unset( $this->cacheTimes[$evictKey] );
+ }
+ }
+
/**
* Push an entry to the top of the cache
*