function Cache::gc
Return value
bool
File
-
vendor/
composer/ composer/ src/ Composer/ Cache.php, line 303
Class
- Cache
- Reads/writes to a filesystem cache
Namespace
ComposerCode
public function gc(int $ttl, int $maxSize) {
if ($this->isEnabled() && !$this->readOnly) {
$expire = new \DateTime();
$expire->modify('-' . $ttl . ' seconds');
$finder = $this->getFinder()
->date('until ' . $expire->format('Y-m-d H:i:s'));
foreach ($finder as $file) {
$this->filesystem
->unlink($file->getPathname());
}
$totalSize = $this->filesystem
->size($this->root);
if ($totalSize > $maxSize) {
$iterator = $this->getFinder()
->sortByAccessedTime()
->getIterator();
while ($totalSize > $maxSize && $iterator->valid()) {
$filepath = $iterator->current()
->getPathname();
$totalSize -= $this->filesystem
->size($filepath);
$this->filesystem
->unlink($filepath);
$iterator->next();
}
}
self::$cacheCollected = true;
return true;
}
return false;
}