Permalink
Browse files

added cache reloading when auto_reload is true and an extension has b…

…een modified
  • Loading branch information...
1 parent 620da47 commit d472d21515e6616da447a0bf7c2b891d6b79cd19 @fabpot committed Sep 24, 2011
Showing with 26 additions and 1 deletion.
  1. +1 −0 CHANGELOG
  2. +25 −1 lib/Twig/Environment.php
View
@@ -1,5 +1,6 @@
* 1.3.0
+ * added cache reloading when auto_reload is true and an extension has been modified
* added the possibility to force the escaping of a string already marked as safe (instance of Twig_Markup)
* allowed empty templates to be used as traits
* added traits support for the "parent" function
@@ -301,7 +301,7 @@ public function loadTemplate($name)
if (false === $cache = $this->getCacheFilename($name)) {
eval('?>'.$this->compileSource($this->loader->getSource($name), $name));
} else {
- if (!is_file($cache) || ($this->isAutoReload() && !$this->loader->isFresh($name, filemtime($cache)))) {
+ if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
$this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $name));
}
@@ -316,6 +316,30 @@ public function loadTemplate($name)
return $this->loadedTemplates[$cls] = new $cls($this);
}
+ /**
+ * Returns true if the template is still fresh.
+ *
+ * Besides checking the loader for freshness information,
+ * this method also checks if the enabled extensions have
+ * not changed.
+ *
+ * @param string $name The template name
+ * @param timestamp $time The last modification time of the cached template
+ *
+ * @return Boolean true if the template is fresh, false otherwise
+ */
+ public function isTemplateFresh($name, $time)
+ {
+ foreach ($this->extensions as $extension) {
+ $r = new ReflectionObject($extension);
+ if (filemtime($r->getFileName()) > $time) {
+ return false;
+ }
+ }
+
+ return $this->loader->isFresh($name, $time);
+ }
+
public function resolveTemplate($names)
{
if (!is_array($names)) {

0 comments on commit d472d21

Please sign in to comment.