- bugfix cache lock was not handled correctly after timeout when $cache_locking == true

This commit is contained in:
Uwe Tews
2015-05-10 12:08:47 +02:00
parent 5ce5d4df49
commit b0ca67b213

View File

@@ -139,23 +139,18 @@ class Smarty_Template_Cached
* Check if cache is valid, lock cache if required * Check if cache is valid, lock cache if required
* *
* @param \Smarty_Internal_Template $_template * @param \Smarty_Internal_Template $_template
* @param bool $lock keep cache locked
* *
* @return bool flag true if cache is valid * @return bool flag true if cache is valid
*/ */
public function isCached(Smarty_Internal_Template $_template, $lock = false) public function isCached(Smarty_Internal_Template $_template)
{ {
if ($this->valid === true) { if ($this->valid !== null) {
return true; return $this->valid;
}
$force = $_template->smarty->force_compile || $_template->smarty->force_cache;
if (!$lock && ($force || !$_template->caching)) {
return $this->valid = false;
} }
while (true) { while (true) {
while (true) { while (true) {
$this->handler->populate($this, $_template); $this->handler->populate($this, $_template);
if ($this->timestamp === false || $_template->smarty->force_compile || $_template->smarty->force_cache) { if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
$this->valid = false; $this->valid = false;
} else { } else {
$this->valid = true; $this->valid = true;
@@ -187,6 +182,7 @@ class Smarty_Template_Cached
Smarty_Internal_Debug::end_cache($_template); Smarty_Internal_Debug::end_cache($_template);
} }
} else { } else {
$this->is_locked = true;
continue; continue;
} }
} else { } else {
@@ -195,15 +191,16 @@ class Smarty_Template_Cached
if ($this->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']))) {
$this->valid = false; $this->valid = false;
} }
if (!$this->valid && $_template->smarty->cache_locking) { if ($_template->smarty->cache_locking) {
if (!$this->valid) {
$this->handler->acquireLock($_template->smarty, $this); $this->handler->acquireLock($_template->smarty, $this);
} elseif ($this->is_locked) {
return $this->valid; $this->handler->releaseLock($_template->smarty, $this);
} else {
return $this->valid;
} }
} }
return $this->valid =false; return $this->valid;
}
return $this->valid = false;
} }
/** /**