diff --git a/change_log.txt b/change_log.txt index 87d0e8d1..0e56d0ab 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@  ===== 3.1.22-dev ===== (xx.xx.2015) 06.05.2015 - bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates + - bugfix/improvement in 3.1.22-dev cache locking did not work as expected 05.05.2015 - optimization on cache update when main template is modified diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 35db7837..6a807eb0 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/27'; + const SMARTY_VERSION = '3.1.22-dev/28'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 72ed7692..de794517 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -61,7 +61,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock'; } $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php'; - $cached->exists = is_file($cached->filepath); + $cached->timestamp = $cached->exists = is_file($cached->filepath); if ($cached->exists) { $cached->timestamp = filemtime($cached->filepath); } @@ -113,7 +113,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource $obj = new Smarty_Internal_Write_File(); if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { $cached = $_template->cached; - $cached->timestamp = $cached->exists = is_file( $cached->filepath); + $cached->timestamp = $cached->exists = is_file($cached->filepath); if ($cached->exists) { $cached->timestamp = filemtime($cached->filepath); return true; diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 454828bd..55b3214f 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -603,7 +603,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } else { // file and php types can be checked without loading the respective resource handlers $mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false; - } + } } elseif ($_file_to_check[2] == 'string') { continue; } else { diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index f0c3fd40..b629aedc 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -56,17 +56,18 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) { if ($template === null && $this instanceof $this->template_class) { - return $this->cached->valid; - } - if (!($template instanceof $this->template_class)) { - if ($parent === null) { - $parent = $this; + $template = $this; + } else { + if (!($template instanceof $this->template_class)) { + if ($parent === null) { + $parent = $this; + } + $smarty = isset($this->smarty) ? $this->smarty : $this; + $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); } - $smarty = isset($this->smarty) ? $this->smarty : $this; - $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); } // return cache status of template - return $template->cached->valid; + return $template->cached->isCached($template); } /** @@ -120,7 +121,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param boolean $cacheable if true (default) this fuction is cachable * @param array $cache_attr caching attributes if any * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining * @throws SmartyException when the plugin tag is invalid */ public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) @@ -143,7 +145,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param string $type of plugin * @param string $tag name of plugin * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function unregisterPlugin($type, $tag) { @@ -159,9 +162,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * Registers a resource to fetch a template * * @param string $type name of resource type - * @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated) + * @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource + * (deprecated) * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function registerResource($type, $callback) { @@ -176,7 +181,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @param string $type name of resource type * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function unregisterResource($type) { @@ -194,7 +200,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param string $type name of cache resource type * @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function registerCacheResource($type, Smarty_CacheResource $callback) { @@ -209,7 +216,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @param string $type name of cache resource type * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function unregisterCacheResource($type) { @@ -231,7 +239,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param array $block_methods list of block-methods * * @throws SmartyException - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) { @@ -285,7 +294,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @param string $name object name * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function unregisterObject($name) { @@ -304,7 +314,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param string $class_impl the referenced PHP class to register * * @throws SmartyException - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function registerClass($class_name, $class_impl) { @@ -324,7 +335,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @param callable $callback class/method name * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining * @throws SmartyException if $callback is not callable */ public function registerDefaultPluginHandler($callback) @@ -344,7 +356,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @param callable $callback class/method name * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining * @throws SmartyException if $callback is not callable */ public function registerDefaultTemplateHandler($callback) @@ -358,7 +371,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @param callable $callback class/method name * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining * @throws SmartyException if $callback is not callable */ public function registerDefaultConfigHandler($callback) @@ -373,7 +387,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param string $type filter type * @param callback $callback * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function registerFilter($type, $callback) { @@ -389,7 +404,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param string $type filter type * @param callback $callback * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function unregisterFilter($type, $callback) { @@ -453,7 +469,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @param string $type filter type * @param string $name filter name * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or + * Smarty_Internal_Template) instance for chaining */ public function unloadFilter($type, $name) { diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index 9f35295c..ae8a329a 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -129,10 +129,17 @@ class Smarty_Template_Cached return $cached; } - + /** + * Check if cache is valid, lock cache if required + * + * @param \Smarty_Internal_Template $_template + * @param bool $lock keep cache locked + * + * @return bool flag true if cache is valid + */ public function isCached(Smarty_Internal_Template $_template, $lock = false) { - if ($this->valid !== null) { + if ($this->valid !== null) { return $this->valid; } while (true) { @@ -175,7 +182,7 @@ class Smarty_Template_Cached if ($_template->smarty->cache_locking && !$lock) { $this->handler->releaseLock($_template->smarty, $this); } - return $this->valid; + return $this->valid; } 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;