diff --git a/core/lib/Drupal/Core/Template/TwigCacheChain.php b/core/lib/Drupal/Core/Template/TwigCacheChain.php index 332a02a..fc5c41b 100644 --- a/core/lib/Drupal/Core/Template/TwigCacheChain.php +++ b/core/lib/Drupal/Core/Template/TwigCacheChain.php @@ -23,7 +23,7 @@ class TwigCacheChain implements \Twig_CacheInterface { * Store cache classes internally. * * @param \Twig_CacheInterface[] $caches - * The cache classes to chain. + * The ordered cache classes to chain. */ public function __construct(array $caches) { assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects($caches, \'\\Twig_CacheInterface\')'); @@ -58,8 +58,8 @@ public function load($key) { foreach ($this->caches as $cache) { if ($cache->has($key)) { $cache->load($key); + return; } - return; } } diff --git a/core/lib/Drupal/Core/Template/TwigCacheNull.php b/core/lib/Drupal/Core/Template/TwigCacheNull.php new file mode 100644 index 0000000..3992836 --- /dev/null +++ b/core/lib/Drupal/Core/Template/TwigCacheNull.php @@ -0,0 +1,22 @@ +buffer[$key]); + } + +} diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 405284d..e59b4ac 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -59,8 +59,11 @@ public function __construct($root, CacheBackendInterface $cache, $twig_extension // Ensure autoescaping is always on. $options['autoescape'] = 'html'; + // We set up a chain of cache classes in case there is a failure or race + // condition. The null cache is roughly equivalent to disabling the Twig + // cache entirely. $php_storage_cache = new TwigPhpStorageCache($cache, $twig_extension_hash); - $null_cache = new \Twig_Cache_Null(); + $null_cache = new TwigCacheNull(); if ($options['cache'] === TRUE) { $options['cache'] = new TwigCacheChain([$php_storage_cache, $null_cache]);