From 57df382ff2a6a5317bc8691db5e5862fcf9c36ad Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Wed, 6 May 2015 22:10:04 +0200 Subject: [PATCH] - bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates --- change_log.txt | 7 +- libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_internal_template.php | 9 ++- libs/sysplugins/smarty_template_cached.php | 70 +++++++++++--------- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/change_log.txt b/change_log.txt index 1505c073..87d0e8d1 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,10 @@  ===== 3.1.22-dev ===== (xx.xx.2015) + 06.05.2015 + - bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates + 05.05.2015 - - optimization on cache update when main template is modified - - optimization move handling from parser to new compiler module + - optimization on cache update when main template is modified + - optimization move handling from parser to new compiler module 05.05.2015 - bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 7b15be37..35db7837 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.22-dev/26'; + const SMARTY_VERSION = '3.1.22-dev/27'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index d47613f9..454828bd 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -223,10 +223,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $this->caching = false; } // read from cache or render - if ($this->caching && !isset($this->cached)) { - $this->cached = Smarty_Template_Cached::load($this); - } $isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED; + if ($isCacheTpl) { + if (!isset($this->cached)) { + $this->cached = Smarty_Template_Cached::load($this); + } + $this->cached->isCached($this, true); + } if (!($isCacheTpl) || !$this->cached->valid) { if ($isCacheTpl) { $this->properties['tpl_function'] = array(); diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index 8721e2ca..9f35295c 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -49,7 +49,7 @@ class Smarty_Template_Cached * * @var boolean */ - public $valid = false; + public $valid = null; /** * Cache was processed @@ -121,45 +121,50 @@ class Smarty_Template_Cached static function load(Smarty_Internal_Template $_template) { $_template->cached = $cached = new Smarty_Template_Cached($_template); - - // - // check if cache is valid - // + $cached->handler->populate($cached, $_template); + // caching enabled ? if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) { - $cached->handler->populate($cached, $_template); + $cached->valid = false; + } + return $cached; + } - return $cached; + + public function isCached(Smarty_Internal_Template $_template, $lock = false) + { + if ($this->valid !== null) { + return $this->valid; } while (true) { while (true) { - $cached->handler->populate($cached, $_template); - if ($cached->timestamp === false || $_template->smarty->force_compile || $_template->smarty->force_cache) { - $cached->valid = false; + if ($this->timestamp === false || $_template->smarty->force_compile || $_template->smarty->force_cache) { + $this->valid = false; } else { - $cached->valid = true; + $this->valid = true; } - if ($cached->valid && $_template->source->timestamp > $cached->timestamp) { - $cached->valid = false; + if ($this->valid && $_template->source->timestamp > $this->timestamp) { + $this->valid = false; } - if ($cached->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > ($cached->timestamp + $_template->cache_lifetime)) { + if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)) { // lifetime expired - $cached->valid = false; + $this->valid = false; } - if ($cached->valid || !$_template->smarty->cache_locking) { + if ($this->valid || !$_template->smarty->cache_locking) { break; } - if (!$cached->handler->locked($_template->smarty, $cached)) { - $cached->handler->acquireLock($_template->smarty, $cached); - break 2; + if (!$this->handler->locked($_template->smarty, $this)) { + $this->handler->acquireLock($_template->smarty, $this); + break; } + $this->handler->populate($this, $_template); } - if ($cached->valid) { - if (!$_template->smarty->cache_locking || $cached->handler->locked($_template->smarty, $cached) === null) { + if ($this->valid) { + if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) { // load cache file for the following checks if ($_template->smarty->debugging) { Smarty_Internal_Debug::start_cache($_template); } - $cached->process($_template); + $this->process($_template); if ($_template->smarty->debugging) { Smarty_Internal_Debug::end_cache($_template); } @@ -167,18 +172,21 @@ class Smarty_Template_Cached continue; } } else { - return $cached; + if ($_template->smarty->cache_locking && !$lock) { + $this->handler->releaseLock($_template->smarty, $this); + } + return $this->valid; } - if ($cached->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) { - $cached->valid = false; + if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) { + $this->valid = false; } - if (!$cached->valid && $_template->smarty->cache_locking) { - $cached->handler->acquireLock($_template->smarty, $cached); - - return $cached; - } else { - return $cached; + if (!$this->valid && $_template->smarty->cache_locking && $lock) { + $this->handler->acquireLock($_template->smarty, $this); } + if ($_template->smarty->cache_locking && !$lock) { + $this->handler->releaseLock($_template->smarty, $this); + } + return $this->valid; } }