Skip to content

Commit

Permalink
Merge pull request #550 from glensc/lessphp-cache
Browse files Browse the repository at this point in the history
lessphp: use updated timestamp from cache
  • Loading branch information
glensc committed Oct 16, 2016
2 parents a9891a0 + 72dd4db commit 2809e3c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/Minify/LessCssSource.php
Expand Up @@ -30,13 +30,7 @@ public function __construct(array $spec, Minify_CacheInterface $cache) {
public function getLastModified() {
$cache = $this->getCache();

$lastModified = 0;
foreach ($cache['files'] as $mtime) {
$lastModified = max($lastModified, $mtime);

}

return $lastModified;
return $cache['lastModified'];
}

/**
Expand Down Expand Up @@ -76,12 +70,29 @@ private function getCache() {
$cache = $less->cachedCompile($input);

if (!is_array($input) || $cache['updated'] > $input['updated']) {
$cache['lastModified'] = $this->getMaxLastModified($cache);
$this->cache->store($cacheId, serialize($cache));
}

return $this->parsed = $cache;
}

/**
* Calculate maximum last modified of all files,
* as the 'updated' timestamp in cache is not the same as file last modified timestamp:
* @link https://github.com/leafo/lessphp/blob/v0.4.0/lessc.inc.php#L1904
* @return int
*/
private function getMaxLastModified($cache)
{
$lastModified = 0;
foreach ($cache['files'] as $mtime) {
$lastModified = max($lastModified, $mtime);
}

return $lastModified;
}

/**
* Make a unique cache id for for this source.
*
Expand All @@ -92,7 +103,7 @@ private function getCache() {
private function getCacheId($prefix = 'minify') {
$md5 = md5($this->filepath);

return "{$prefix}_less_{$md5}";
return "{$prefix}_less2_{$md5}";
}

/**
Expand Down

0 comments on commit 2809e3c

Please sign in to comment.