main
Jordi Boggiano 12 years ago
parent 6ce285b70c
commit 514a3cde77

@ -114,7 +114,7 @@ class Cache
return false;
}
public function gc($ttl, $cacheMaxSize)
public function gc($ttl, $maxSize)
{
$expire = new \DateTime();
$expire->modify('-'.$ttl.' seconds');
@ -124,12 +124,12 @@ class Cache
unlink($file->getRealPath());
}
$totalCacheSize = $this->filesystem->size($this->root);
if ($totalCacheSize > $cacheMaxSize) {
$totalSize = $this->filesystem->size($this->root);
if ($totalSize > $maxSize) {
$iterator = $this->getFinder()->sortByAccessedTime()->getIterator();
while ($totalCacheSize > $cacheMaxSize && $iterator->valid()) {
while ($totalSize > $maxSize && $iterator->valid()) {
$filepath = $iterator->current()->getRealPath();
$totalCacheSize -= $this->filesystem->size($filepath);
$totalSize -= $this->filesystem->size($filepath);
unlink($filepath);
$iterator->next();
}

@ -141,7 +141,7 @@ class Config
case 'cache-files-maxsize':
if (!preg_match('/^\s*(\d+)\s*([kmg]ib)?\s*$/i', $this->config[$key], $matches)) {
throw new \RuntimeException(
"composer.json contains invalid 'cache-files-maxsize' value: {$this->config[$key]}"
"Could not parse the value of 'cache-files-maxsize' from your config: {$this->config[$key]}"
);
}
$size = $matches[1];
@ -155,6 +155,7 @@ class Config
$size *= 1024;
}
}
return $size;
case 'cache-files-ttl':

@ -284,6 +284,7 @@ class Filesystem
if (is_dir($path)) {
return $this->directorySize($path);
}
return filesize($path);
}
@ -298,6 +299,7 @@ class Filesystem
$size += $file->getSize();
}
}
return $size;
}

@ -128,4 +128,3 @@ class FilesystemTest extends TestCase
$this->assertGreaterThanOrEqual(10, $fs->size("$tmp/composer_testdir"));
}
}

Loading…
Cancel
Save