Skip to content

Commit

Permalink
Remove old cache files if succesfully written
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvandiepen1 committed Nov 23, 2015
1 parent 1765388 commit f6d93d3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Less.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f6d93d3

Please sign in to comment.