Enable template caching.

This commit is contained in:
flash 2018-09-17 21:07:10 +02:00
parent af222dfbd8
commit 5556a9789a
2 changed files with 23 additions and 3 deletions

View file

@ -44,6 +44,8 @@ define('NODE_MODULES_DIR', __DIR__ . '/node_modules');
define('NODE_DEST_CSS', CSS_DIR . '/libraries.css');
define('NODE_DEST_JS', JS_DIR . '/libraries.js');
define('TWIG_DIRECTORY', sys_get_temp_dir() . '/msz-tpl-cache-' . md5(__DIR__));
/**
* FUNCTIONS
*/
@ -71,8 +73,14 @@ function deleteAllFilesInDir(string $dir, string $pattern): void
$files = globDir($dir, $pattern);
foreach ($files as $file) {
unlink($file);
misuzu_log("Deleted '{$file}'");
if (is_dir($file)) {
misuzu_log("'{$file}' is a directory, entering...");
deleteAllFilesInDir($file, $pattern);
rmdir($file);
} else {
unlink($file);
misuzu_log("Deleted '{$file}'");
}
}
}
@ -149,3 +157,11 @@ foreach (IMPORT_SEQ as $sequence) {
file_put_contents($sequence['destination'], $contents);
}
// no need to do this in debug mode, auto reload is enabled and cache is disabled
if (!file_exists(__DIR__ . '/.debug')) {
// Clear Twig cache
misuzu_log();
misuzu_log('Deleting template cache');
deleteAllFilesInDir(TWIG_DIRECTORY, '*');
}

View file

@ -226,7 +226,11 @@ MIG;
$app->startCache();
tpl_init(['debug' => MSZ_DEBUG]);
tpl_init([
'debug' => MSZ_DEBUG,
'auto_reload' => MSZ_DEBUG,
'cache' => MSZ_DEBUG ? false : create_directory(build_path(sys_get_temp_dir(), 'msz-tpl-cache-' . md5(__DIR__))),
]);
tpl_var('globals', $app->getSiteInfo());