optimize template object caching

This commit is contained in:
Uwe Tews
2015-08-06 19:25:00 +02:00
parent 16fc95ccf7
commit de49865d22
2 changed files with 24 additions and 42 deletions

View File

@@ -1315,24 +1315,10 @@ class Smarty extends Smarty_Internal_TemplateBase
} else {
$data = null;
}
$_templateId = $this->getTemplateId($template, $cache_id, $compile_id);
if (isset($this->template_objects[$_templateId])) {
if ($do_clone) {
$tpl = clone $this->template_objects[$_templateId];
$tpl->smarty = clone $tpl->smarty;
} else {
$tpl = $this->template_objects[$_templateId];
}
$tpl->parent = $parent;
$tpl->tpl_vars = array();
$tpl->config_vars = array();
} else {
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
if ($do_clone) {
$tpl->smarty = clone $tpl->smarty;
}
$tpl->templateId = $_templateId;
}
// fill data if present
if (!empty($data) && is_array($data)) {
// set up variable values
@@ -1610,7 +1596,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function __destruct()
{
$i =0;// intentionally left blank
$i = 0;// intentionally left blank
}
/**

View File

@@ -41,13 +41,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public $template_resource = null;
/**
* Saved template Id
*
* @var null|string
*/
public $templateId = null;
/**
* flag if compiled template is invalid and must be (re)compiled
*
@@ -494,6 +487,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
{
$tpl = $_templateId = null;
if ($this->smarty->template_resource_caching) {
$_templateId = $this->getTemplateId($template, $cache_id, $compile_id);
// already in template cache?
if (isset($this->smarty->template_objects[$_templateId])) {
@@ -505,9 +500,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
$tpl->caching = $caching;
$tpl->cache_lifetime = $cache_lifetime;
} else {
}
}
if (!isset($tpl)) {
$tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime);
$tpl->templateId = $_templateId;
if ($this->smarty->template_resource_caching && !$tpl->source->recompiled) {
$this->smarty->template_objects[$_templateId] = $tpl;
}
}
// get variables from calling scope
if ($parent_scope == Smarty::SCOPE_LOCAL) {
@@ -551,9 +550,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope);
$tpl->properties['nocache_hash'] = $hash;
if (!isset($this->smarty->template_objects[$tpl->templateId])) {
$this->smarty->template_objects[$tpl->templateId] = $tpl;
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_template($tpl);
Smarty_Internal_Debug::start_render($tpl);