- bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates

This commit is contained in:
Uwe Tews
2015-05-06 22:10:04 +02:00
parent d92714cc7e
commit 57df382ff2
4 changed files with 51 additions and 37 deletions

View File

@@ -1,7 +1,10 @@
 ===== 3.1.22-dev ===== (xx.xx.2015)  ===== 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 05.05.2015
- optimization on cache update when main template is modified - optimization on cache update when main template is modified
- optimization move <?php ?> handling from parser to new compiler module - optimization move <?php ?> handling from parser to new compiler module
05.05.2015 05.05.2015
- bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23 - bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23

View File

@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.22-dev/26'; const SMARTY_VERSION = '3.1.22-dev/27';
/** /**
* define variable scopes * define variable scopes

View File

@@ -223,10 +223,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->caching = false; $this->caching = false;
} }
// read from cache or render // 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; $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->cached->valid) {
if ($isCacheTpl) { if ($isCacheTpl) {
$this->properties['tpl_function'] = array(); $this->properties['tpl_function'] = array();

View File

@@ -49,7 +49,7 @@ class Smarty_Template_Cached
* *
* @var boolean * @var boolean
*/ */
public $valid = false; public $valid = null;
/** /**
* Cache was processed * Cache was processed
@@ -121,45 +121,50 @@ class Smarty_Template_Cached
static function load(Smarty_Internal_Template $_template) static function load(Smarty_Internal_Template $_template)
{ {
$_template->cached = $cached = new Smarty_Template_Cached($_template); $_template->cached = $cached = new Smarty_Template_Cached($_template);
$cached->handler->populate($cached, $_template);
// // caching enabled ?
// check if cache is valid
//
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) { 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) {
while (true) { while (true) {
$cached->handler->populate($cached, $_template); if ($this->timestamp === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
if ($cached->timestamp === false || $_template->smarty->force_compile || $_template->smarty->force_cache) { $this->valid = false;
$cached->valid = false;
} else { } else {
$cached->valid = true; $this->valid = true;
} }
if ($cached->valid && $_template->source->timestamp > $cached->timestamp) { if ($this->valid && $_template->source->timestamp > $this->timestamp) {
$cached->valid = false; $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 // lifetime expired
$cached->valid = false; $this->valid = false;
} }
if ($cached->valid || !$_template->smarty->cache_locking) { if ($this->valid || !$_template->smarty->cache_locking) {
break; break;
} }
if (!$cached->handler->locked($_template->smarty, $cached)) { if (!$this->handler->locked($_template->smarty, $this)) {
$cached->handler->acquireLock($_template->smarty, $cached); $this->handler->acquireLock($_template->smarty, $this);
break 2; break;
} }
$this->handler->populate($this, $_template);
} }
if ($cached->valid) { if ($this->valid) {
if (!$_template->smarty->cache_locking || $cached->handler->locked($_template->smarty, $cached) === null) { if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
// load cache file for the following checks // load cache file for the following checks
if ($_template->smarty->debugging) { if ($_template->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template); Smarty_Internal_Debug::start_cache($_template);
} }
$cached->process($_template); $this->process($_template);
if ($_template->smarty->debugging) { if ($_template->smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template); Smarty_Internal_Debug::end_cache($_template);
} }
@@ -167,18 +172,21 @@ class Smarty_Template_Cached
continue; continue;
} }
} else { } 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']))) { if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) {
$cached->valid = false; $this->valid = false;
} }
if (!$cached->valid && $_template->smarty->cache_locking) { if (!$this->valid && $_template->smarty->cache_locking && $lock) {
$cached->handler->acquireLock($_template->smarty, $cached); $this->handler->acquireLock($_template->smarty, $this);
return $cached;
} else {
return $cached;
} }
if ($_template->smarty->cache_locking && !$lock) {
$this->handler->releaseLock($_template->smarty, $this);
}
return $this->valid;
} }
} }