diff --git a/change_log.txt b/change_log.txt index 3642dfbe..8b1d7eb1 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +01/02/2009 +- update cached_timestamp at the template object after cache file is written to avoid possible side effects +- use internally always SMARTY_CACHING_LIFETIME_* constants + 01/01/2009 - bugfix for obtaining plugins which must be included (related to change of 12/30/2009) - bugfix for {php} tag (trow an exception if allow_php_tag = false) diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index d8f39642..072ea537 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -65,11 +65,13 @@ class Smarty_Internal_CacheResource_File { public function writeCachedContent($template, $content) { if (!$template->resource_object->isEvaluated) { - return Smarty_Internal_Write_File::writeFile($template->getCachedFilepath(), $content, $this->smarty); - } else { - return false; - } - } + if (Smarty_Internal_Write_File::writeFile($template->getCachedFilepath(), $content, $this->smarty) === true) { + $template->cached_timestamp = filemtime($template->getCachedFilepath()); + return true; + } + } + return false; + } /** * Empty cache folder diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 3458c0e4..6ca41323 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -50,7 +50,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { public $rendered_content = null; // Cache file private $cached_filepath = null; - private $cached_timestamp = null; + public $cached_timestamp = null; private $isCached = null; private $cache_resource_object = null; private $cacheFileWritten = false; @@ -103,7 +103,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { throw new Exception ("Unable to parse resource name \"{$template_resource}\""); } // load cache resource - if (!$this->resource_object->isEvaluated && ($this->caching == 1 || $this->caching == 2)) { + if (!$this->resource_object->isEvaluated && ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) { $this->cache_resource_object = $this->smarty->loadCacheResource(); } } @@ -291,7 +291,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { public function getCachedFilepath () { return $this->cached_filepath === null ? - $this->cached_filepath = ($this->resource_object->isEvaluated || !($this->caching == 1 || $this->caching == 2)) ? false : $this->cache_resource_object->getCachedFilepath($this) : + $this->cached_filepath = ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedFilepath($this) : $this->cached_filepath; } @@ -305,7 +305,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { public function getCachedTimestamp () { return $this->cached_timestamp === null ? - $this->cached_timestamp = ($this->resource_object->isEvaluated || !($this->caching == 1 || $this->caching == 2)) ? false : $this->cache_resource_object->getCachedTimestamp($this) : + $this->cached_timestamp = ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedTimestamp($this) : $this->cached_timestamp; } @@ -317,7 +317,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { public function getCachedContent () { return $this->rendered_content === null ? - $this->rendered_content = ($this->resource_object->isEvaluated || !($this->caching == 1 || $this->caching == 2)) ? false : $this->cache_resource_object->getCachedContents($this) : + $this->rendered_content = ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedContents($this) : $this->rendered_content; } @@ -326,7 +326,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { */ public function writeCachedContent () { - if ($this->resource_object->isEvaluated || !($this->caching == 1 || $this->caching == 2)) { + if ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) { // don't write cache file return false; } @@ -361,7 +361,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { { if ($this->isCached === null) { $this->isCached = false; - if (($this->caching == 1 || $this->caching == 2) && !$this->resource_object->isEvaluated && !$this->force_compile && !$this->force_cache) { + if (($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED) && !$this->resource_object->isEvaluated && !$this->force_compile && !$this->force_cache) { $cachedTimestamp = $this->getCachedTimestamp(); if ($cachedTimestamp === false) { return $this->isCached;