diff --git a/change_log.txt b/change_log.txt index 82da50a4..2ad3e1f4 100644 --- a/change_log.txt +++ b/change_log.txt @@ -5,6 +5,7 @@ - cache template object of {include} if same template is included several times - convert debug console processing to object - use output buffers for better performance and less memory usage + - optimize nocache hash processing 06.08.2015 - avoid possible circular object references caused by parser/lexer objects diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 2ff631dd..a4c2495d 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -308,15 +308,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase if ($this->smarty->debugging) { $this->smarty->_debug->end_cache($this); } - } else { - if ($this->parent instanceof Smarty_Internal_Template && !empty($this->compiled->nocache_hash) && - !empty($this->parent->compiled->nocache_hash) - ) { - // replace nocache_hash - $content = str_replace("{$this->compiled->nocache_hash}", $this->parent->compiled->nocache_hash, $content); - $this->parent->compiled->has_nocache_code = $this->parent->compiled->has_nocache_code || - $this->compiled->has_nocache_code; - } } } else { if ($this->smarty->debugging) { @@ -588,7 +579,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $this->smarty->_debug->end_template($tpl); $this->smarty->_debug->end_render($tpl); } - return str_replace($tpl->compiled->nocache_hash, $this->compiled->nocache_hash, $output); + if ($caching == 9999 && $tpl->compiled->has_nocache_code) { + $this->cached->hashes[$tpl->compiled->nocache_hash] = true; + } } /** diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index b9682715..d2f54c36 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -65,6 +65,13 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base */ public $source = null; + /** + * Nocache hash codes of processed compiled templates + * + * @var array + */ + public $hashes = array(); + /** * create Cached Object container * @@ -264,14 +271,21 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base * Sanitize content and write it to cache resource * * @param Smarty_Internal_Template $_template - * @param string $content * @param bool $no_output_filter * - * @throws SmartyException + * @throws \SmartyException */ public function updateCache(Smarty_Internal_Template $_template, $no_output_filter) { $content = ob_get_clean(); + unset($this->hashes[$_template->compiled->nocache_hash]); + if (!empty($this->hashes)) { + $hash_array = array(); + foreach ($this->hashes as $hash => $foo) { + $hash_array[] = "/{$hash}/"; + } + $content = preg_replace($hash_array, $_template->compiled->nocache_hash, $content); + } $_template->cached->has_nocache_code = false; // get text between non-cached items $cache_split = preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", $content); diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 5aec3a99..8ecbeccc 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -207,6 +207,9 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base $_template->cached->file_dependency = array_merge($_template->cached->file_dependency, $this->file_dependency); } $_template->getRenderedTemplateCode($this->unifunc); + if ($_template->caching && $this->has_nocache_code) { + $_template->cached->hashes[$this->nocache_hash] = true; + } } /**