diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 49816ed9d..a5b0883ba 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -48,6 +48,7 @@ class Twig_Environment private $originalCache; private $bcWriteCacheFile = false; private $bcGetCacheFilename = false; + private $lastModifiedExtension = 0; /** * Constructor. @@ -454,14 +455,16 @@ class Twig_Environment */ public function isTemplateFresh($name, $time) { - foreach ($this->extensions as $extension) { - $r = new ReflectionObject($extension); - if (filemtime($r->getFileName()) > $time) { - return false; + if(0 === $this->lastModifiedExtension) { + foreach ($this->extensions as $extension) { + $r = new ReflectionObject($extension); + if (($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) { + $this->lastModifiedExtension = $extensionTime; + } } } - return $this->getLoader()->isFresh($name, $time); + return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time); } /** @@ -767,6 +770,8 @@ class Twig_Environment throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); } + $this->lastModifiedExtension = 0; + $this->extensions[$extension->getName()] = $extension; }