diff --git a/src/Less.php b/src/Less.php index 178ebfb..d99111a 100644 --- a/src/Less.php +++ b/src/Less.php @@ -39,7 +39,12 @@ public function compile($filename, $options = array()) { foreach($this->jobs as $i => $job) { call_user_func_array(array($parser, array_shift($job)), $job); } - return $this->writeCss($output_path, $parser->getCss()); + $written = $this->writeCss($output_path, $parser->getCss()); + // Remove old cache files if succesfully written + if ($written === true) { + $this->cleanCache(); + } + return $written; } /** @@ -64,6 +69,14 @@ protected function writeCss($output_path, $css) { return file_put_contents($output_path, $css) !== false; } + /** + * Clean cache + */ + protected function cleanCache() { + \Less_Cache::$gc_lifetime = 2; // Inchangeable? + \Less_Cache::CleanCache(); + } + /** * Recompile CSS if needed * @param string $filename CSS filename without extension @@ -100,11 +113,6 @@ public function recompile($filename, $recompile = null, $options = array()) { default: throw new \Exception('Unknown \'' . $recompile . '\' LESS_RECOMPILE setting'); } - if ($this->recompiled === true) { - // Remove old cache files - \Less_Cache::$gc_lifetime = 0; - \Less_Cache::CleanCache(); - } return $this->recompiled; }