protected $memCache;
/** @var BagOStuff */
protected $srvCache;
- /** @var ProcessCacheLRU Map of paths to small (RAM/disk) cache items */
+ /** @var MapCacheLRU Map of paths to small (RAM/disk) cache items */
protected $cheapCache;
- /** @var ProcessCacheLRU Map of paths to large (RAM/disk) cache items */
+ /** @var MapCacheLRU Map of paths to large (RAM/disk) cache items */
protected $expensiveCache;
/** @var array Map of container names to sharding config */
$this->mimeCallback = $config['mimeCallback'] ?? null;
$this->srvCache = new EmptyBagOStuff(); // disabled by default
$this->memCache = WANObjectCache::newEmpty(); // disabled by default
- $this->cheapCache = new ProcessCacheLRU( self::CACHE_CHEAP_SIZE );
- $this->expensiveCache = new ProcessCacheLRU( self::CACHE_EXPENSIVE_SIZE );
+ $this->cheapCache = new MapCacheLRU( self::CACHE_CHEAP_SIZE );
+ $this->expensiveCache = new MapCacheLRU( self::CACHE_EXPENSIVE_SIZE );
}
/**
}
$ps = $this->scopedProfileSection( __METHOD__ . "-{$this->name}" );
$latest = !empty( $params['latest'] ); // use latest data?
- if ( !$latest && !$this->cheapCache->has( $path, 'stat', self::CACHE_TTL ) ) {
+ if ( !$latest && !$this->cheapCache->hasField( $path, 'stat', self::CACHE_TTL ) ) {
$this->primeFileCache( [ $path ] ); // check persistent cache
}
- if ( $this->cheapCache->has( $path, 'stat', self::CACHE_TTL ) ) {
- $stat = $this->cheapCache->get( $path, 'stat' );
+ if ( $this->cheapCache->hasField( $path, 'stat', self::CACHE_TTL ) ) {
+ $stat = $this->cheapCache->getField( $path, 'stat' );
// If we want the latest data, check that this cached
// value was in fact fetched with the latest available data.
if ( is_array( $stat ) ) {
if ( is_array( $stat ) ) { // file exists
// Strongly consistent backends can automatically set "latest"
$stat['latest'] = $stat['latest'] ?? $latest;
- $this->cheapCache->set( $path, 'stat', $stat );
+ $this->cheapCache->setField( $path, 'stat', $stat );
$this->setFileCache( $path, $stat ); // update persistent cache
if ( isset( $stat['sha1'] ) ) { // some backends store SHA-1 as metadata
- $this->cheapCache->set( $path, 'sha1',
+ $this->cheapCache->setField( $path, 'sha1',
[ 'hash' => $stat['sha1'], 'latest' => $latest ] );
}
if ( isset( $stat['xattr'] ) ) { // some backends store headers/metadata
$stat['xattr'] = self::normalizeXAttributes( $stat['xattr'] );
- $this->cheapCache->set( $path, 'xattr',
+ $this->cheapCache->setField( $path, 'xattr',
[ 'map' => $stat['xattr'], 'latest' => $latest ] );
}
} elseif ( $stat === false ) { // file does not exist
- $this->cheapCache->set( $path, 'stat', $latest ? 'NOT_EXIST_LATEST' : 'NOT_EXIST' );
- $this->cheapCache->set( $path, 'xattr', [ 'map' => false, 'latest' => $latest ] );
- $this->cheapCache->set( $path, 'sha1', [ 'hash' => false, 'latest' => $latest ] );
+ $this->cheapCache->setField( $path, 'stat', $latest ? 'NOT_EXIST_LATEST' : 'NOT_EXIST' );
+ $this->cheapCache->setField( $path, 'xattr', [ 'map' => false, 'latest' => $latest ] );
+ $this->cheapCache->setField( $path, 'sha1', [ 'hash' => false, 'latest' => $latest ] );
$this->logger->debug( __METHOD__ . ": File $path does not exist.\n" );
} else { // an error occurred
$this->logger->warning( __METHOD__ . ": Could not stat file $path.\n" );
}
$ps = $this->scopedProfileSection( __METHOD__ . "-{$this->name}" );
$latest = !empty( $params['latest'] ); // use latest data?
- if ( $this->cheapCache->has( $path, 'xattr', self::CACHE_TTL ) ) {
- $stat = $this->cheapCache->get( $path, 'xattr' );
+ if ( $this->cheapCache->hasField( $path, 'xattr', self::CACHE_TTL ) ) {
+ $stat = $this->cheapCache->getField( $path, 'xattr' );
// If we want the latest data, check that this cached
// value was in fact fetched with the latest available data.
if ( !$latest || $stat['latest'] ) {
}
$fields = $this->doGetFileXAttributes( $params );
$fields = is_array( $fields ) ? self::normalizeXAttributes( $fields ) : false;
- $this->cheapCache->set( $path, 'xattr', [ 'map' => $fields, 'latest' => $latest ] );
+ $this->cheapCache->setField( $path, 'xattr', [ 'map' => $fields, 'latest' => $latest ] );
return $fields;
}
}
$ps = $this->scopedProfileSection( __METHOD__ . "-{$this->name}" );
$latest = !empty( $params['latest'] ); // use latest data?
- if ( $this->cheapCache->has( $path, 'sha1', self::CACHE_TTL ) ) {
- $stat = $this->cheapCache->get( $path, 'sha1' );
+ if ( $this->cheapCache->hasField( $path, 'sha1', self::CACHE_TTL ) ) {
+ $stat = $this->cheapCache->getField( $path, 'sha1' );
// If we want the latest data, check that this cached
// value was in fact fetched with the latest available data.
if ( !$latest || $stat['latest'] ) {
}
}
$hash = $this->doGetFileSha1Base36( $params );
- $this->cheapCache->set( $path, 'sha1', [ 'hash' => $hash, 'latest' => $latest ] );
+ $this->cheapCache->setField( $path, 'sha1', [ 'hash' => $hash, 'latest' => $latest ] );
return $hash;
}
$path = self::normalizeStoragePath( $src );
if ( $path === null ) {
$fsFiles[$src] = null; // invalid storage path
- } elseif ( $this->expensiveCache->has( $path, 'localRef' ) ) {
- $val = $this->expensiveCache->get( $path, 'localRef' );
+ } elseif ( $this->expensiveCache->hasField( $path, 'localRef' ) ) {
+ $val = $this->expensiveCache->getField( $path, 'localRef' );
// If we want the latest data, check that this cached
// value was in fact fetched with the latest available data.
if ( !$latest || $val['latest'] ) {
foreach ( $this->doGetLocalReferenceMulti( $params ) as $path => $fsFile ) {
$fsFiles[$path] = $fsFile;
if ( $fsFile ) { // update the process cache...
- $this->expensiveCache->set( $path, 'localRef',
+ $this->expensiveCache->setField( $path, 'localRef',
[ 'object' => $fsFile, 'latest' => $latest ] );
}
}
}
// Enlarge the cache to fit the stat entries of these files
- $this->cheapCache->resize( max( 2 * count( $paths ), self::CACHE_CHEAP_SIZE ) );
+ $this->cheapCache->setMaxSize( max( 2 * count( $paths ), self::CACHE_CHEAP_SIZE ) );
// Load from the persistent container caches
$this->primeContainerCache( $paths );
$status->success = $subStatus->success; // not done in merge()
// Shrink the stat cache back to normal size
- $this->cheapCache->resize( self::CACHE_CHEAP_SIZE );
+ $this->cheapCache->setMaxSize( self::CACHE_CHEAP_SIZE );
return $status;
}
if ( is_array( $stat ) ) { // file exists
// Strongly consistent backends can automatically set "latest"
$stat['latest'] = $stat['latest'] ?? $latest;
- $this->cheapCache->set( $path, 'stat', $stat );
+ $this->cheapCache->setField( $path, 'stat', $stat );
$this->setFileCache( $path, $stat ); // update persistent cache
if ( isset( $stat['sha1'] ) ) { // some backends store SHA-1 as metadata
- $this->cheapCache->set( $path, 'sha1',
+ $this->cheapCache->setField( $path, 'sha1',
[ 'hash' => $stat['sha1'], 'latest' => $latest ] );
}
if ( isset( $stat['xattr'] ) ) { // some backends store headers/metadata
$stat['xattr'] = self::normalizeXAttributes( $stat['xattr'] );
- $this->cheapCache->set( $path, 'xattr',
+ $this->cheapCache->setField( $path, 'xattr',
[ 'map' => $stat['xattr'], 'latest' => $latest ] );
}
} elseif ( $stat === false ) { // file does not exist
- $this->cheapCache->set( $path, 'stat',
+ $this->cheapCache->setField( $path, 'stat',
$latest ? 'NOT_EXIST_LATEST' : 'NOT_EXIST' );
- $this->cheapCache->set( $path, 'xattr',
+ $this->cheapCache->setField( $path, 'xattr',
[ 'map' => false, 'latest' => $latest ] );
- $this->cheapCache->set( $path, 'sha1',
+ $this->cheapCache->setField( $path, 'sha1',
[ 'hash' => false, 'latest' => $latest ] );
$this->logger->debug( __METHOD__ . ": File $path does not exist.\n" );
} else { // an error occurred
$path = $pathNames[$cacheKey];
if ( is_array( $val ) ) {
$val['latest'] = false; // never completely trust cache
- $this->cheapCache->set( $path, 'stat', $val );
+ $this->cheapCache->setField( $path, 'stat', $val );
if ( isset( $val['sha1'] ) ) { // some backends store SHA-1 as metadata
- $this->cheapCache->set( $path, 'sha1',
+ $this->cheapCache->setField( $path, 'sha1',
[ 'hash' => $val['sha1'], 'latest' => false ] );
}
if ( isset( $val['xattr'] ) ) { // some backends store headers/metadata
$val['xattr'] = self::normalizeXAttributes( $val['xattr'] );
- $this->cheapCache->set( $path, 'xattr',
+ $this->cheapCache->setField( $path, 'xattr',
[ 'map' => $val['xattr'], 'latest' => false ] );
}
}
$this->memCache = $config['wanCache'];
}
// Process cache for container info
- $this->containerStatCache = new ProcessCacheLRU( 300 );
+ $this->containerStatCache = new MapCacheLRU( 300 );
// Cache auth token information to avoid RTTs
if ( !empty( $config['cacheAuthInfo'] ) && isset( $config['srvCache'] ) ) {
$this->srvCache = $config['srvCache'];
* @param array $val Stat value
*/
public function loadListingStatInternal( $path, array $val ) {
- $this->cheapCache->set( $path, 'stat', $val );
+ $this->cheapCache->setField( $path, 'stat', $val );
}
protected function doGetFileXAttributes( array $params ) {
// Set the file stat process cache in passing
$stat = $this->getStatFromHeaders( $rhdrs );
$stat['latest'] = $isLatest;
- $this->cheapCache->set( $path, 'stat', $stat );
+ $this->cheapCache->setField( $path, 'stat', $stat );
} elseif ( $rcode === 404 ) {
$tmpFiles[$path] = false;
} else {
if ( $bypassCache ) { // purge cache
$this->containerStatCache->clear( $container );
- } elseif ( !$this->containerStatCache->has( $container, 'stat' ) ) {
+ } elseif ( !$this->containerStatCache->hasField( $container, 'stat' ) ) {
$this->primeContainerCache( [ $container ] ); // check persistent cache
}
- if ( !$this->containerStatCache->has( $container, 'stat' ) ) {
+ if ( !$this->containerStatCache->hasField( $container, 'stat' ) ) {
$auth = $this->getAuthentication();
if ( !$auth ) {
return null;
if ( $bypassCache ) {
return $stat;
} else {
- $this->containerStatCache->set( $container, 'stat', $stat ); // cache it
+ $this->containerStatCache->setField( $container, 'stat', $stat ); // cache it
$this->setContainerCache( $container, $stat ); // update persistent cache
}
} elseif ( $rcode === 404 ) {
}
}
- return $this->containerStatCache->get( $container, 'stat' );
+ return $this->containerStatCache->getField( $container, 'stat' );
}
/**
protected function doPrimeContainerCache( array $containerInfo ) {
foreach ( $containerInfo as $container => $info ) {
- $this->containerStatCache->set( $container, 'stat', $info );
+ $this->containerStatCache->setField( $container, 'stat', $info );
}
}