diff --git a/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php b/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php index 1f5e77c..a894793 100644 --- a/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php +++ b/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php @@ -94,15 +94,7 @@ public function has($key) { * {@inheritdoc} */ public function load($key) { - // if (!$this->storage()->load($key)) { - if (TRUE) { - // eval() the stored template since we were not able to load it from - // storage. - // - // This only works when the PhpStorage cache is cold, it does not help us - // if has() returns TRUE because then write() is not called. :( - eval('?>' . $this->templateSourceCache[$key]); - } + $this->storage()->load($key); } /** @@ -120,6 +112,13 @@ public function write($key, $content) { /** * {@inheritdoc} */ + public function fallback($key, $content) { + eval('?' . '>' . $content); + } + + /** + * {@inheritdoc} + */ public function getTimestamp($key) { $cid = 'twig:' . $key; if ($cache = $this->cache->get($cid)) { diff --git a/core/vendor/twig/twig/lib/Twig/Cache/Filesystem.php b/core/vendor/twig/twig/lib/Twig/Cache/Filesystem.php index c33fa90..71fbb90 100644 --- a/core/vendor/twig/twig/lib/Twig/Cache/Filesystem.php +++ b/core/vendor/twig/twig/lib/Twig/Cache/Filesystem.php @@ -96,6 +96,13 @@ public function write($key, $content) /** * {@inheritdoc} */ + public function fallback($key, $content) { + return; + } + + /** + * {@inheritdoc} + */ public function getTimestamp($key) { return filemtime($key); diff --git a/core/vendor/twig/twig/lib/Twig/Cache/Null.php b/core/vendor/twig/twig/lib/Twig/Cache/Null.php index 6a9a29b..725104c 100644 --- a/core/vendor/twig/twig/lib/Twig/Cache/Null.php +++ b/core/vendor/twig/twig/lib/Twig/Cache/Null.php @@ -55,6 +55,13 @@ public function load($key) /** * {@inheritdoc} */ + public function fallback($key, $content) { + return; + } + + /** + * {@inheritdoc} + */ public function getTimestamp($key) { // never called as has() always returns false diff --git a/core/vendor/twig/twig/lib/Twig/CacheInterface.php b/core/vendor/twig/twig/lib/Twig/CacheInterface.php index fedd366..4d7fc5b 100644 --- a/core/vendor/twig/twig/lib/Twig/CacheInterface.php +++ b/core/vendor/twig/twig/lib/Twig/CacheInterface.php @@ -55,6 +55,14 @@ public function write($key, $content); public function load($key); /** + * Handles when the cache is not available. + * + * @param string $key The cache key + * @param string $content The template representation as a PHP class + */ + public function fallback($key, $content); + + /** * Returns the modification timestamp of a key. * * @param string $key The cache key diff --git a/core/vendor/twig/twig/lib/Twig/Environment.php b/core/vendor/twig/twig/lib/Twig/Environment.php index 565ec47..be952b3 100644 --- a/core/vendor/twig/twig/lib/Twig/Environment.php +++ b/core/vendor/twig/twig/lib/Twig/Environment.php @@ -384,6 +384,10 @@ public function loadTemplate($name, $index = null) } $this->cache->load($key); + + if (!class_exists($cls, FALSE)) { + $this->cache->fallback($key, $this->compileSource($this->getLoader()->getSource($name), $name)); + } } if (!$this->runtimeInitialized) {