mirror of
https://github.com/mrclay/minify.git
synced 2025-08-12 09:05:08 +02:00
Merge pull request #550 from glensc/lessphp-cache
lessphp: use updated timestamp from cache
This commit is contained in:
@@ -30,13 +30,7 @@ class Minify_LessCssSource extends Minify_Source {
|
|||||||
public function getLastModified() {
|
public function getLastModified() {
|
||||||
$cache = $this->getCache();
|
$cache = $this->getCache();
|
||||||
|
|
||||||
$lastModified = 0;
|
return $cache['lastModified'];
|
||||||
foreach ($cache['files'] as $mtime) {
|
|
||||||
$lastModified = max($lastModified, $mtime);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $lastModified;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,12 +70,29 @@ class Minify_LessCssSource extends Minify_Source {
|
|||||||
$cache = $less->cachedCompile($input);
|
$cache = $less->cachedCompile($input);
|
||||||
|
|
||||||
if (!is_array($input) || $cache['updated'] > $input['updated']) {
|
if (!is_array($input) || $cache['updated'] > $input['updated']) {
|
||||||
|
$cache['lastModified'] = $this->getMaxLastModified($cache);
|
||||||
$this->cache->store($cacheId, serialize($cache));
|
$this->cache->store($cacheId, serialize($cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->parsed = $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.
|
* Make a unique cache id for for this source.
|
||||||
*
|
*
|
||||||
@@ -92,7 +103,7 @@ class Minify_LessCssSource extends Minify_Source {
|
|||||||
private function getCacheId($prefix = 'minify') {
|
private function getCacheId($prefix = 'minify') {
|
||||||
$md5 = md5($this->filepath);
|
$md5 = md5($this->filepath);
|
||||||
|
|
||||||
return "{$prefix}_less_{$md5}";
|
return "{$prefix}_less2_{$md5}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user