1
0
Fork 0

Cache: clear cache using removeDirectory

pull/6460/head
Brandon Max 2017-05-31 22:02:15 -04:00
parent 27ee47def7
commit 24b8fea48a
3 changed files with 27 additions and 4 deletions

View File

@ -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) {

View File

@ -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>');

View File

@ -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");
}
}
}