浏览代码

Merge pull request #3175 from Petah/clear-cache

Clear all the caches
Jordi Boggiano 10 年之前
父节点
当前提交
2cb64c8a72
共有 1 个文件被更改,包括 22 次插入13 次删除
  1. 22 13
      src/Composer/Command/ClearCacheCommand.php

+ 22 - 13
src/Composer/Command/ClearCacheCommand.php

@@ -40,21 +40,30 @@ EOT
     {
     {
         $config = Factory::createConfig();
         $config = Factory::createConfig();
         $io = $this->getIO();
         $io = $this->getIO();
-        
-        $cachePath = realpath($config->get('cache-repo-dir'));
-        if (!$cachePath) {
-            $io->write('<info>Cache directory does not exist.</info>');
-            return;
-        }
 
 
-        $cache = new Cache($io, $cachePath);
-        if (!$cache->isEnabled()) {
-            $io->write('<info>Cache is not enabled.</info>');
-            return;
+        $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'),
+        );
+
+        foreach ($cachePaths as $key => $cachePath) {
+            $cachePath = realpath($cachePath);
+            if (!$cachePath) {
+                $io->write("<info>Cache directory does not exist ($key): $cachePath</info>");
+                return;
+            }
+            $cache = new Cache($io, $cachePath);
+            if (!$cache->isEnabled()) {
+                $io->write("<info>Cache is not enabled ($key): $cachePath</info>");
+                return;
+            }
+
+            $io->write("<info>Clearing cache ($key): $cachePath</info>");
+            $cache->gc(0, 0);
         }
         }
 
 
-        $io->write('<info>Clearing cache in: '.$cachePath.'</info>');
-        $cache->gc(0, 0);
-        $io->write('<info>Cache cleared.</info>');
+        $io->write('<info>All caches cleared.</info>');
     }
     }
 }
 }