Skip to content

Commit

Permalink
Activate Twig Cache on production only
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Mar 24, 2024
1 parent e2731fa commit 004122a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.phplint-cache
.phpunit.result.cache
cache/*.cache
cache/twig/
composer.phar
public/assets/bootstrap/
public/assets/font-awesome/
Expand Down
15 changes: 11 additions & 4 deletions app/classes/ReleaseInsights/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Template
*/
public function __construct(public string $template, public array $data)
{
// Cache compiled templates on production
$this->template_caching = PRODUCTION ? CACHE_PATH : false;
// Cache compiled templates on production in a twig folder (10x difference)
$this->template_caching = PRODUCTION ? CACHE_PATH . 'twig/' : false;

// @codeCoverageIgnoreStart
// Pass extra variables to template in local dev mode
Expand All @@ -41,10 +41,17 @@ public function render(): void
// @codeCoverageIgnoreStart
// Allow Twig debug mode in local dev mode
if (LOCALHOST && !defined('TESTING_CONTEXT')) {
$twig = new Environment($twig_loader, ['debug' => true,]);
$twig = new Environment(
$twig_loader,
[
'cache' => $this->template_caching,
'debug' => true,
'auto_reload' => true,
]
);
$twig->addExtension(new \Twig\Extension\DebugExtension());
} else {
$twig = new Environment($twig_loader);
$twig = new Environment($twig_loader, ['cache' => $this->template_caching,]);
}
// @codeCoverageIgnoreEnd

Expand Down

0 comments on commit 004122a

Please sign in to comment.