Add new config cms.forceBytecodeInvalidation

Refs #2385
This commit is contained in:
Samuel Georges 2017-01-31 07:23:12 +11:00
parent 8caf3c5d02
commit b2301a8056
3 changed files with 28 additions and 7 deletions

View File

@ -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,
];

View File

@ -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);
}
}
}

View File

@ -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);