pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
387 stars 42 forks source link

Force clear cache #130

Closed sandrodz closed 7 years ago

sandrodz commented 7 years ago

In production its nice to set upToDateCheck to false. But flipping false/true when there are some minor edits deployed can easily become annoying. Laravel has cache:clear artisan command.

Is it possible to implement something similar for pug-php? any ideas?

I thought clearing cache dir would force cache recreation even with upToDateCheck to false but it errors out instead.

kylekatarnls commented 7 years ago

1/ cache:clear laravel command will clear pug cache if you use the dedicated adapter for Laravel: https://github.com/BKWLD/laravel-pug or if you set the cache directory in /var/cache 2/ hot fix in production is a very bad practice as editing options on the fly. Prefer using a proper deploy process for every change you deploy on production 3/ 'upToDateCheck' => false suppose you use $pug->cacheDirectory('path/to/pug/templates') to update your cache directory on deploy

So you should never edit your options in the PHP code and you even don't need to clear cache, to refresh your pug cache, just execute this code on each deploy:

$pug = new Pug(array(
    'cache' => 'var/cache/pug',
);
list($success, $errors) = $pug->cacheDirectory('path/to/pug/templates');
echo "$success files have been cached\n";
echo "$errors errors occurred\n";

This can be put in a PHP file you can call in CLI or in your deployment process.

sandrodz commented 7 years ago
  1. Not using laravel, unfortunately
  2. Of course
  3. This is exactly what I needed, thank you!

I just noticed that you've this in docs too, sorry for not reading readme fully.

kylekatarnls commented 7 years ago

I now the README become very big. I will try to do a more structured documentation for the next version. Thanks.

kylekatarnls commented 6 years ago

[UPDATE] There is now a command to generate/regenerate the cache directory: http://localhost:9000/#compile-directory-or-cache-directory