diff --git a/config/cms.php b/config/cms.php index a56d7b2b0..645497a93 100644 --- a/config/cms.php +++ b/config/cms.php @@ -316,4 +316,16 @@ return [ 'enableCsrfProtection' => false, + /* + |-------------------------------------------------------------------------- + | Force bytecode invalidation + |-------------------------------------------------------------------------- + | + | When using OPcache with opcache.validate_timestamps set to 0 or APC + | with apc.stat set to 0 and Twig cache enabled, clearing the template + | cache won't update the cache, set to true to get around this. + | + */ + + 'forceBytecodeInvalidation' => true, ]; diff --git a/modules/cms/classes/CodeParser.php b/modules/cms/classes/CodeParser.php index e34699abc..100628a88 100644 --- a/modules/cms/classes/CodeParser.php +++ b/modules/cms/classes/CodeParser.php @@ -334,11 +334,13 @@ class CodeParser /* * Compile cached file into bytecode cache */ - if (function_exists('opcache_invalidate')) { - opcache_invalidate($path, true); - } - elseif (function_exists('apc_compile_file')) { - apc_compile_file($path); + if (Config::get('cms.forceBytecodeInvalidation', false)) { + if (function_exists('opcache_invalidate')) { + opcache_invalidate($path, true); + } + elseif (function_exists('apc_compile_file')) { + apc_compile_file($path); + } } } diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index c1bd4d3ba..b2421d1c2 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -15,6 +15,7 @@ use Response; use Exception; use BackendAuth; use Twig_Environment; +use Twig_Cache_Filesystem; use Cms\Twig\Loader as TwigLoader; use Cms\Twig\DebugExtension; use Cms\Twig\Extension as CmsTwigExtension; @@ -484,14 +485,20 @@ class Controller { $this->loader = new TwigLoader; + $useCache = !Config::get('cms.twigNoCache'); $isDebugMode = Config::get('app.debug', false); + $forceBytecode = Config::get('cms.forceBytecodeInvalidation', false); $options = [ 'auto_reload' => true, 'debug' => $isDebugMode, ]; - if (!Config::get('cms.twigNoCache')) { - $options['cache'] = storage_path().'/cms/twig'; + + if ($useCache) { + $options['cache'] = new Twig_Cache_Filesystem( + storage_path().'/cms/twig', + $forceBytecode ? Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION : 0 + ); } $this->twig = new Twig_Environment($this->loader, $options);