mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- optimize nocache hash processing
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
- cache template object of {include} if same template is included several times
|
- cache template object of {include} if same template is included several times
|
||||||
- convert debug console processing to object
|
- convert debug console processing to object
|
||||||
- use output buffers for better performance and less memory usage
|
- use output buffers for better performance and less memory usage
|
||||||
|
- optimize nocache hash processing
|
||||||
|
|
||||||
06.08.2015
|
06.08.2015
|
||||||
- avoid possible circular object references caused by parser/lexer objects
|
- avoid possible circular object references caused by parser/lexer objects
|
||||||
|
@@ -308,15 +308,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
$this->smarty->_debug->end_cache($this);
|
$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 {
|
} else {
|
||||||
if ($this->smarty->debugging) {
|
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_template($tpl);
|
||||||
$this->smarty->_debug->end_render($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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -65,6 +65,13 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
|||||||
*/
|
*/
|
||||||
public $source = null;
|
public $source = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nocache hash codes of processed compiled templates
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $hashes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create Cached Object container
|
* 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
|
* Sanitize content and write it to cache resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template
|
* @param Smarty_Internal_Template $_template
|
||||||
* @param string $content
|
|
||||||
* @param bool $no_output_filter
|
* @param bool $no_output_filter
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function updateCache(Smarty_Internal_Template $_template, $no_output_filter)
|
public function updateCache(Smarty_Internal_Template $_template, $no_output_filter)
|
||||||
{
|
{
|
||||||
$content = ob_get_clean();
|
$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;
|
$_template->cached->has_nocache_code = false;
|
||||||
// get text between non-cached items
|
// get text between non-cached items
|
||||||
$cache_split = preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", $content);
|
$cache_split = preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", $content);
|
||||||
|
@@ -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->cached->file_dependency = array_merge($_template->cached->file_dependency, $this->file_dependency);
|
||||||
}
|
}
|
||||||
$_template->getRenderedTemplateCode($this->unifunc);
|
$_template->getRenderedTemplateCode($this->unifunc);
|
||||||
|
if ($_template->caching && $this->has_nocache_code) {
|
||||||
|
$_template->cached->hashes[$this->nocache_hash] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user