Skip to content

Commit

Permalink
Added manifest JSON cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaljurecko committed Aug 31, 2017
1 parent 24e47fd commit 3cbef23
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Webrouse/AssetMacro/AssetMacro.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AssetMacro extends MacroSet

const CONFIG_PROVIDER = 'assetMacroConfig';

private static $manifestCache = [];

/**
* @param Latte\Compiler $compiler
Expand Down Expand Up @@ -202,7 +203,7 @@ private static function autodetectManifest($asset, $wwwDir, $need, array $config
foreach ($autodetectPaths as $path) {
$path = $dir . DIRECTORY_SEPARATOR . $path;
if (file_exists($path)) {
return Json::decode(file_get_contents($path), Json::FORCE_ARRAY);
return self::getManifest($path);
}
}

Expand All @@ -217,6 +218,18 @@ private static function autodetectManifest($asset, $wwwDir, $need, array $config
return NULL;
}

/**
* Get manifest content and cache it
* @param string $path
* @return array
*/
private static function getManifest($path) {
if (!isset(self::$manifestCache[$path])) {
self::$manifestCache[$path] = Json::decode(file_get_contents($path), Json::FORCE_ARRAY);
}
return self::$manifestCache[$path];
}


/**
* @param null|array $manifest Array of revisions
Expand Down

0 comments on commit 3cbef23

Please sign in to comment.