*/
class ClearCacheCommand extends BaseCommand
{
protected function configure(): void
{
$this
->setName('clear-cache')
->setAliases(['clearcache', 'cc'])
->setDescription('Clears composer\'s internal package cache')
->setDefinition([
new InputOption('gc', null, InputOption::VALUE_NONE, 'Only run garbage collection, not a full cache clear'),
])
->setHelp(
"The clear-cache deletes all cached packages from composer's\ncache directory.\n\nRead more at https://getcomposer.org/doc/03-cli.md#clear-cache-clearcache-cc"
)
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$config = Factory::createConfig();
$io = $this->getIO();
$cachePaths = [
'cache-vcs-dir' => $config->get('cache-vcs-dir'),
'cache-repo-dir' => $config->get('cache-repo-dir'),
'cache-files-dir' => $config->get('cache-files-dir'),
'cache-dir' => $config->get('cache-dir'),
];
foreach ($cachePaths as $key => $cachePath) {
// only individual dirs get garbage collected
if ($key === 'cache-dir' && $input->getOption('gc')) {
continue;
}
$cachePath = realpath($cachePath);
if (!$cachePath) {
$io->writeError("Cache directory does not exist ($key): $cachePath");
continue;
}
$cache = new Cache($io, $cachePath);
$cache->setReadOnly($config->get('cache-read-only'));
if (!$cache->isEnabled()) {
$io->writeError("Cache is not enabled ($key): $cachePath");
continue;
}
if ($input->getOption('gc')) {
$io->writeError("Garbage-collecting cache ($key): $cachePath");
if ($key === 'cache-files-dir') {
$cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
} elseif ($key === 'cache-repo-dir') {
$cache->gc($config->get('cache-ttl'), 1024 * 1024 * 1024 /* 1GB, this should almost never clear anything that is not outdated */);
} elseif ($key === 'cache-vcs-dir') {
$cache->gcVcsCache($config->get('cache-ttl'));
}
} else {
$io->writeError("Clearing cache ($key): $cachePath");
$cache->clear();
}
}
if ($input->getOption('gc')) {
$io->writeError('All caches garbage-collected.');
} else {
$io->writeError('All caches cleared.');
}
return 0;
}
}
__halt_compiler();----SIGNATURE:----A9p9UBlY7Y5DBCEQtFU3/miWGiBP60+4DizD8fKyTY/U+jbXt+6k2O2YCwkv8FFgns2j7Hq0H/JQtFjcqXu+6Hzw4fREDxadcgr2WVFm8MVIOY6Bl6oDp+sXYOfwio4GtBGUVExOLTsnUt0evJvjDGV6AbU1NpMcOszQzmgzW2ujpr/JNTmymWEfDrOxDT3/QnLfI5gUt3s2+x+7QzDPsk/QsmG2Dp2t9FnT6tIy7ghX9JeDQrLbGAv72zFKdlzVnUdrq2F/wvwydw4nLkRE/er7D6KNT6xVcmhROaNnESpr6Ppz1GTZvUZ6gLmBDQnWKmN0fU38y2SC1ql/AB87NK397DuuMFyYZVMNfoj482b08WoaXQBi4MZjmLnXpKm1FKWJg/LmU/3bzggn+wThTdJAoAoU/fi7aUkq7TAZOXHNZt71wyQuk/f0H/qWCqjBfQICFqw59yAMlo2jkcz0smCt0oZA10sHR9UePZPRXTPRMTBmNB08STIsksi+XXLz7xWggHQTzDLqLUTnzyLANPsahCK195wN7xFfGgSdxoKSQZKIIFJSj9dH9jbwqOx7RzRd/DR/qzvVX8wEkA8TDGsAa96DITpVHUgB3mAqM2SAShgRgXfdrHNdRjUrHu6U/qbpjJFMi9rCWGPla19YUpYQsaSLNPVvTJULotFzQkw=----ATTACHMENT:----MzQ0MTA1MTAzNDQ5MTM0MCAxMjc2MTE4NDc2NDk0ODEwIDg5MzY2NjMzMTM3NDkyODg=