* @ingroup FileRepo
*/
class RepoGroup {
-
/**
* @var LocalRepo
*/
* @var RepoGroup
*/
protected static $instance;
- const MAX_CACHE_SIZE = 1000;
+ const MAX_CACHE_SIZE = 500;
/**
* Get a RepoGroup instance. At present only one instance of RepoGroup is
&& empty( $options['private'] )
&& empty( $options['bypassCache'] ) )
{
- $useCache = true;
$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
- $tmp = $this->cache[$dbkey];
- unset( $this->cache[$dbkey] );
- $this->cache[$dbkey] = $tmp;
+ $this->pingCache( $dbkey );
# Return the entry
return $this->cache[$dbkey][$time];
- } else {
- # Add a negative cache entry, may be overridden
- $this->trimCache();
- $this->cache[$dbkey][$time] = false;
- $cacheEntry =& $this->cache[$dbkey][$time];
}
+ $useCache = true;
} else {
$useCache = false;
}
# Check the local repo
$image = $this->localRepo->findFile( $title, $options );
- if ( $image ) {
- if ( $useCache ) {
- $cacheEntry = $image;
- }
- return $image;
- }
# Check the foreign repos
- foreach ( $this->foreignRepos as $repo ) {
- $image = $repo->findFile( $title, $options );
- if ( $image ) {
- if ( $useCache ) {
- $cacheEntry = $image;
+ if ( !$image ) {
+ foreach ( $this->foreignRepos as $repo ) {
+ $image = $repo->findFile( $title, $options );
+ if ( $image ) {
+ break;
}
- return $image;
}
}
- # Not found, do not override negative cache
- return false;
+
+ $image = $image ? $image : false; // type sanity
+ # Cache file existence or non-existence
+ if ( $useCache && ( !$image || $image->isCacheable() ) ) {
+ $this->trimCache();
+ $this->cache[$dbkey][$time] = $image;
+ }
+
+ return $image;
}
function findFiles( $inputItems ) {
}
}
+ /**
+ * 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
*/
* @ingroup FileAbstraction
*/
class LocalFile extends File {
+ const CACHE_FIELD_MAX_LEN = 1000;
+
/**#@+
* @private
*/
);
if ( $dbw->affectedRows() == 0 ) {
- # (bug 34993) Note: $oldver can be empty here, if the previous
- # version of the file was broken. Allow registration of the new
- # version to continue anyway, because that's better than having
+ # (bug 34993) Note: $oldver can be empty here, if the previous
+ # version of the file was broken. Allow registration of the new
+ # version to continue anyway, because that's better than having
# an image that's not fixable by user operations.
$reupload = true;
return $this->sha1;
}
+ function isCacheable() {
+ $this->load();
+ return strlen( $this->metadata ) <= self::CACHE_FIELD_MAX_LEN; // avoid OOMs
+ }
+
/**
* Start a transaction and lock the image for update
* Increments a reference counter if the lock is already held