/** @var array */
protected $foreignInfo;
- /** @var array */
+ /** @var ProcessCacheLRU */
protected $cache;
/** @var RepoGroup */
function __construct( $localInfo, $foreignInfo ) {
$this->localInfo = $localInfo;
$this->foreignInfo = $foreignInfo;
- $this->cache = array();
+ $this->cache = new ProcessCacheLRU( self::MAX_CACHE_SIZE );
}
/**
) {
$time = isset( $options['time'] ) ? $options['time'] : '';
$dbkey = $title->getDBkey();
- if ( isset( $this->cache[$dbkey][$time] ) ) {
- wfDebug( __METHOD__ . ": got File:$dbkey from process cache\n" );
- # Move it to the end of the list so that we can delete the LRU entry later
- $this->pingCache( $dbkey );
-
- # Return the entry
- return $this->cache[$dbkey][$time];
+ if ( $this->cache->has( $dbkey, $time, 60 ) ) {
+ return $this->cache->get( $dbkey, $time );
}
$useCache = true;
} else {
$image = $image ? $image : false; // type sanity
# Cache file existence or non-existence
if ( $useCache && ( !$image || $image->isCacheable() ) ) {
- $this->trimCache();
- $this->cache[$dbkey][$time] = $image;
+ $this->cache->set( $dbkey, $time, $image );
}
return $image;
}
/**
+ * Search repositories for many files at once.
+ *
+ * @param array $items An array of titles, or an array of findFile() options with
+ * the "title" option giving the title. Example:
+ *
+ * $findItem = array( 'title' => $title, 'private' => true );
+ * $findBatch = array( $findItem );
+ * $repo->findFiles( $findBatch );
+ *
+ * No title should appear in $items twice, as the result use titles as keys
+ * @param int $flags Supports:
+ * - FileRepo::NAME_AND_TIME_ONLY : return a (search title => (title,timestamp)) map.
+ * The search title uses the input titles; the other is the final post-redirect title.
+ * All titles are returned as string DB keys and the inner array is associative.
+ * @return array Map of (file name => File objects) for matches
+ *
* @param array $inputItems
+ * @param integer $flags
* @return array
*/
- function findFiles( $inputItems ) {
+ function findFiles( array $inputItems, $flags = 0 ) {
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
}
}
- $images = $this->localRepo->findFiles( $items );
+ $images = $this->localRepo->findFiles( $items, $flags );
foreach ( $this->foreignRepos as $repo ) {
// Remove found files from $items
unset( $items[$name] );
}
- $images = array_merge( $images, $repo->findFiles( $items ) );
+ $images = array_merge( $images, $repo->findFiles( $items, $flags ) );
}
return $images;
}
}
- /**
- * Move a cache entry to the top (such as when accessed)
- */
- protected function pingCache( $key ) {
- if ( isset( $this->cache[$key] ) ) {
- $tmp = $this->cache[$key];
- unset( $this->cache[$key] );
- $this->cache[$key] = $tmp;
- }
- }
-
- /**
- * Limit cache memory
- */
- protected function trimCache() {
- while ( count( $this->cache ) >= self::MAX_CACHE_SIZE ) {
- reset( $this->cache );
- $key = key( $this->cache );
- wfDebug( __METHOD__ . ": evicting $key\n" );
- unset( $this->cache[$key] );
- }
- }
-
/**
* Clear RepoGroup process cache used for finding a file
* @param Title|null $title Title of the file or null to clear all files
*/
public function clearCache( Title $title = null ) {
if ( $title == null ) {
- $this->cache = array();
+ $this->cache->clear();
} else {
- $dbKey = $title->getDBkey();
- if ( isset( $this->cache[$dbKey] ) ) {
- unset( $this->cache[$dbKey] );
- }
+ $this->cache->clear( $title->getDBkey() );
}
}
}