Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement caching for on-demand compiling with plessc #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions plessc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ Options include:
-f=format Set the output format, includes "default", "compressed"
-c Keep /* */ comments in output
-r Read from STDIN instead of input-file
-q Quick compile mode (enable caching). Unavailable for -T or -X
-w Watch input-file, and compile to output-file if it is changed
-T Dump formatted parse tree
-X Dump raw parse tree


EOT;

$opts = getopt('hvrwncXTf:', array('help'));
while (count($argv) > 0 && preg_match('/^-([-hvrwncXT]$|[f]=)/', $argv[0])) {
$opts = getopt('hvrqwncXTf:', array('help'));
while (count($argv) > 0 && preg_match('/^-([-hvrqwncXT]$|[f]=)/', $argv[0])) {
array_shift($argv);
}

Expand Down Expand Up @@ -232,6 +233,25 @@ try {
$out = print_r($tree, 1);
else
$out = dumpValue($tree)."\n";
} elseif (has("q")) {

$fcache = $fname . ".lessphp";
$cache = null;

if (file_exists($fcache)) {
$cache = @unserialize(file_get_contents($fcache));
}
if (!is_array($cache)) {
$cache = $fname;
}

$cache_new = $less->cachedCompile($cache);
$out = $cache_new["compiled"];

if (!is_array($cache) || ($cache_new["updated"] > $cache["updated"])) {
file_put_contents($fcache, serialize($cache_new));
}

} else {
$out = $less->parse();
}
Expand Down