From 11fed2c8ce3dd38fe686e7b27db738f64373fe3d Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Sun, 22 Dec 2024 13:13:25 +0100 Subject: Add template caching --- src/application/appdef.php | 2 +- src/application/templates/old/base.twig | 3 +++ src/index.php | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/application/appdef.php b/src/application/appdef.php index 6c69ee8..1f51d97 100644 --- a/src/application/appdef.php +++ b/src/application/appdef.php @@ -1,3 +1,3 @@ Debug mode + {% endif %}
diff --git a/src/index.php b/src/index.php index 5350680..8036a19 100644 --- a/src/index.php +++ b/src/index.php @@ -27,6 +27,7 @@ if (($_SERVER["HTTP_USER_AGENT"] ?? "") === "") { } define("REGISTRATION_ENABLED", isTrue(env("REGISTRATION_ENABLED") ?? "")); +define("DEBUG", isTrue(env("DEBUG") ?? "")); const __ROOT__ = __DIR__; @@ -172,9 +173,11 @@ function render(string $page, array $context = [], array $functions = []): void $loader = new FilesystemLoader([ $templateDir . "/" . $currentTemplate, ]); - $twig = new Environment($loader, [ - // TODO Enable caching - ]); + $twigEnvConfig = []; + if (!DEBUG) { + $twigEnvConfig["cache"] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "mybb-template-cache"; + } + $twig = new Environment($loader, $twigEnvConfig); $twig->addFunction(new TwigFunction("__", __(...), [ "is_safe" => ["html"] ])); $twig->addFunction(new TwigFunction("___", ___(...), [ "is_safe" => ["html"] ])); -- cgit v1.2.3 |