1
0
Fork 0

Merge pull request #6460 from bmax/master

Cache: clear cache using removeDirectory
pull/6499/head
Jordi Boggiano 2017-06-17 15:28:05 +02:00 committed by GitHub
commit 91a4e76958
3 changed files with 27 additions and 4 deletions

View File

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

View File

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

View File

@ -107,4 +107,18 @@ class CacheTest extends TestCase
} }
$this->assertFileExists("{$this->root}/cached.file3.zip"); $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");
}
}
} }