- 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)
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 <?php ?> handling from parser to new compiler module
- optimization on cache update when main template is modified
- optimization move <?php ?> 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

View File

@@ -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

View File

@@ -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();

View File

@@ -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;
}
}