Skip to content

Commit 24b8fea

Browse files
committed
Cache: clear cache using removeDirectory
1 parent 27ee47d commit 24b8fea

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/Composer/Cache.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ public function remove($file)
175175
return false;
176176
}
177177

178+
public function clear()
179+
{
180+
if ($this->enabled) {
181+
return $this->filesystem->removeDirectory($this->root);
182+
}
183+
184+
return false;
185+
}
186+
178187
public function gc($ttl, $maxSize)
179188
{
180189
if ($this->enabled) {

src/Composer/Command/ClearCacheCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
4242
$io = $this->getIO();
4343

4444
$cachePaths = array(
45-
'cache-dir' => $config->get('cache-dir'),
46-
'cache-files-dir' => $config->get('cache-files-dir'),
47-
'cache-repo-dir' => $config->get('cache-repo-dir'),
4845
'cache-vcs-dir' => $config->get('cache-vcs-dir'),
46+
'cache-repo-dir' => $config->get('cache-repo-dir'),
47+
'cache-files-dir' => $config->get('cache-files-dir'),
48+
'cache-dir' => $config->get('cache-dir'),
4949
);
5050

5151
foreach ($cachePaths as $key => $cachePath) {
@@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6363
}
6464

6565
$io->writeError("<info>Clearing cache ($key): $cachePath</info>");
66-
$cache->gc(0, 0);
66+
$cache->clear();
6767
}
6868

6969
$io->writeError('<info>All caches cleared.</info>');

tests/Composer/Test/CacheTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,18 @@ public function testRemoveFilesWhenCacheIsTooLarge()
107107
}
108108
$this->assertFileExists("{$this->root}/cached.file3.zip");
109109
}
110+
111+
public function testClearCache()
112+
{
113+
$this->finder
114+
->method('removeDirectory')
115+
->with($this->root)
116+
->willReturn(true);
117+
118+
$this->assertTrue($this->cache->clear());
119+
120+
for ($i = 0; $i < 3; $i++) {
121+
$this->assertFileNotExists("{$this->root}/cached.file{$i}.zip");
122+
}
123+
}
110124
}

0 commit comments

Comments
 (0)