*/
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:----BdNQCKQml+RS/WybRj2DCiBgV8ZdaW7By8GzmI1nbHJJLh52q3G0Lc1Bu5XeJmp4xBFzo+LhB/6oRE0rAGM7gajiB5jPRoR3pyR3XeOcwP87lG0w9S60cShT9zwKPr+Lu9k0owcIKBW5hdgdt4jE/gH9OM62qwWkYWe8qfYvOMpdHlnSXYm+kJXMG8R+zpLggYa7NwhfX2rFLfuDeooi8DttoekEMADh29ShWKpcp2PJT7josp2LQE12NceCjEdRdT9TnG4OTU4oVyAteuPaFFXRxqcX88TzAzeh5N+eQMWx0VTXXxvqblFQSfO1DGkbCve16HN+No96qtX7ef3i+iwfLOj8x6uL0NTJudwEr7fR92ASrA6dskoA6s7fVJzpYX0PPdTUIUUAjbSC8MbbubHSY7ljSxOdloyis+XdnUx6T6Ab/LeAOinc+QFlmTgaiBQ2bjr6VPs/M4k0AwYO7lOeDCndWVEY0THYpImgLBuM56SwtVeJ1I/dWZ/rH7C5l7mqdas5yxva91GL7l7MLcpZ+0yXseY/dJijHnos3qnrNEY3y5ua6UVqQ5LyP+TkXFJN9mbn9wobkLiOfA6jomZgYni7Cw2MXg/lUzWIN3g02o+Q89e5RphGFLlms9fyrcXdz372uyC3ZAc+5FaCFisQNxt9hZ97fvTmpl5KCZ0=----ATTACHMENT:----NjYwNTM2NDE4MTA2NzI1NSA3NzU5NzIxMzA2NDU2MDQxIDYwNTE5NDc1OTA1NjI4MjI=