From 5556a9789a8ff5c6a68e49c53d11395eab17a358 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 17 Sep 2018 21:07:10 +0200 Subject: [PATCH] Enable template caching. --- build.php | 20 ++++++++++++++++++-- misuzu.php | 6 +++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build.php b/build.php index 6633e277..14e5766b 100644 --- a/build.php +++ b/build.php @@ -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, '*'); +} diff --git a/misuzu.php b/misuzu.php index 3de78cf1..05baf9d4 100644 --- a/misuzu.php +++ b/misuzu.php @@ -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());