Cache: clear cache using removeDirectory

main
Brandon Max 7 years ago
parent 27ee47def7
commit 24b8fea48a

@ -175,6 +175,15 @@ class Cache
return false;
}
public function clear()
{
if ($this->enabled) {
return $this->filesystem->removeDirectory($this->root);
}
return false;
}
public function gc($ttl, $maxSize)
{
if ($this->enabled) {

@ -42,10 +42,10 @@ EOT
$io = $this->getIO();
$cachePaths = array(
'cache-dir' => $config->get('cache-dir'),
'cache-files-dir' => $config->get('cache-files-dir'),
'cache-repo-dir' => $config->get('cache-repo-dir'),
'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) {
@ -63,7 +63,7 @@ EOT
}
$io->writeError("<info>Clearing cache ($key): $cachePath</info>");
$cache->gc(0, 0);
$cache->clear();
}
$io->writeError('<info>All caches cleared.</info>');

@ -107,4 +107,18 @@ class CacheTest extends TestCase
}
$this->assertFileExists("{$this->root}/cached.file3.zip");
}
public function testClearCache()
{
$this->finder
->method('removeDirectory')
->with($this->root)
->willReturn(true);
$this->assertTrue($this->cache->clear());
for ($i = 0; $i < 3; $i++) {
$this->assertFileNotExists("{$this->root}/cached.file{$i}.zip");
}
}
}

Loading…
Cancel
Save