mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- move template object cache into static variables
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
===== 3.1.31-dev ===== (xx.xx.xx)
|
===== 3.1.31 ===== (23.11.2016)
|
||||||
19.11.2016
|
23.11.2016
|
||||||
|
- move template object cache into static variables
|
||||||
|
|
||||||
|
19.11.2016
|
||||||
- bugfix inheritance root child templates containing nested {block}{/block} could call sub-bock content from parent
|
- bugfix inheritance root child templates containing nested {block}{/block} could call sub-bock content from parent
|
||||||
template https://github.com/smarty-php/smarty/issues/317
|
template https://github.com/smarty-php/smarty/issues/317
|
||||||
- change version checking
|
- change version checking
|
||||||
|
@@ -108,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.31-dev/46';
|
const SMARTY_VERSION = '3.1.31-dev/47';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
@@ -746,6 +746,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->_clearTemplateCache();
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
if (is_callable('mb_internal_encoding')) {
|
if (is_callable('mb_internal_encoding')) {
|
||||||
mb_internal_encoding(Smarty::$_CHARSET);
|
mb_internal_encoding(Smarty::$_CHARSET);
|
||||||
@@ -1111,13 +1112,13 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
|
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
|
||||||
$tpl = null;
|
$tpl = null;
|
||||||
if ($this->caching && isset($this->_cache[ 'isCached' ][ $_templateId ])) {
|
if ($this->caching && isset(Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) {
|
||||||
$tpl = $do_clone ? clone $this->_cache[ 'isCached' ][ $_templateId ] :
|
$tpl = $do_clone ? clone Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] :
|
||||||
$this->_cache[ 'isCached' ][ $_templateId ];
|
Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
|
||||||
$tpl->inheritance = null;
|
$tpl->inheritance = null;
|
||||||
$tpl->tpl_vars = $tpl->config_vars = array();
|
$tpl->tpl_vars = $tpl->config_vars = array();
|
||||||
} else if (!$do_clone && isset($this->_cache[ 'tplObjects' ][ $_templateId ])) {
|
} else if (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
|
||||||
$tpl = clone $this->_cache[ 'tplObjects' ][ $_templateId ];
|
$tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ];
|
||||||
$tpl->inheritance = null;
|
$tpl->inheritance = null;
|
||||||
$tpl->tpl_vars = $tpl->config_vars = array();
|
$tpl->tpl_vars = $tpl->config_vars = array();
|
||||||
} else {
|
} else {
|
||||||
@@ -1248,8 +1249,8 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function _clearTemplateCache()
|
public function _clearTemplateCache()
|
||||||
{
|
{
|
||||||
$this->_cache[ 'isCached' ] = array();
|
Smarty_Internal_Template::$isCacheTplObj = array();
|
||||||
$this->_cache[ 'tplObjects' ] = array();
|
Smarty_Internal_Template::$tplObjCache = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -102,6 +102,27 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public $endRenderCallbacks = array();
|
public $endRenderCallbacks = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template object cache
|
||||||
|
*
|
||||||
|
* @var Smarty_Internal_Template[]
|
||||||
|
*/
|
||||||
|
public static $tplObjCache = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template object cache for Smarty::isCached() == true
|
||||||
|
*
|
||||||
|
* @var Smarty_Internal_Template[]
|
||||||
|
*/
|
||||||
|
public static $isCacheTplObj = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtemplate Info Cache
|
||||||
|
*
|
||||||
|
* @var string[]int[]
|
||||||
|
*/
|
||||||
|
public static $subTplInfo = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create template data object
|
* Create template data object
|
||||||
* Some of the global Smarty settings copied to template scope
|
* Some of the global Smarty settings copied to template scope
|
||||||
@@ -259,9 +280,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
// recursive call ?
|
// recursive call ?
|
||||||
if (isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId() != $_templateId) {
|
if (isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId() != $_templateId) {
|
||||||
// already in template cache?
|
// already in template cache?
|
||||||
if (isset($smarty->_cache[ 'tplObjects' ][ $_templateId ])) {
|
if (isset(self::$tplObjCache[ $_templateId ])) {
|
||||||
// copy data from cached object
|
// copy data from cached object
|
||||||
$cachedTpl = &$smarty->_cache[ 'tplObjects' ][ $_templateId ];
|
$cachedTpl = &self::$tplObjCache[ $_templateId ];
|
||||||
$tpl->templateId = $cachedTpl->templateId;
|
$tpl->templateId = $cachedTpl->templateId;
|
||||||
$tpl->template_resource = $cachedTpl->template_resource;
|
$tpl->template_resource = $cachedTpl->template_resource;
|
||||||
$tpl->cache_id = $cachedTpl->cache_id;
|
$tpl->cache_id = $cachedTpl->cache_id;
|
||||||
@@ -306,13 +327,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$tpl->cache_lifetime = $cache_lifetime;
|
$tpl->cache_lifetime = $cache_lifetime;
|
||||||
// set template scope
|
// set template scope
|
||||||
$tpl->scope = $scope;
|
$tpl->scope = $scope;
|
||||||
if (!isset($smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
if (!isset(self::$tplObjCache[ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
||||||
// check if template object should be cached
|
// check if template object should be cached
|
||||||
if ($forceTplCache || (isset($smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) &&
|
if ($forceTplCache || (isset(self::$subTplInfo[ $tpl->template_resource ]) &&
|
||||||
$smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1) ||
|
self::$subTplInfo[ $tpl->template_resource ] > 1) ||
|
||||||
($tpl->_isSubTpl() && isset($smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]))
|
($tpl->_isSubTpl() && isset(self::$tplObjCache[ $tpl->parent->templateId ]))
|
||||||
) {
|
) {
|
||||||
$smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
|
self::$tplObjCache[ $tpl->templateId ] = $tpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,10 +381,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
public function _subTemplateRegister()
|
public function _subTemplateRegister()
|
||||||
{
|
{
|
||||||
foreach ($this->compiled->includes as $name => $count) {
|
foreach ($this->compiled->includes as $name => $count) {
|
||||||
if (isset($this->smarty->_cache[ 'subTplInfo' ][ $name ])) {
|
if (isset(self::$subTplInfo[ $name ])) {
|
||||||
$this->smarty->_cache[ 'subTplInfo' ][ $name ] += $count;
|
self::$subTplInfo[ $name ] += $count;
|
||||||
} else {
|
} else {
|
||||||
$this->smarty->_cache[ 'subTplInfo' ][ $name ] = $count;
|
self::$subTplInfo[ $name ] = $count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,7 +451,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
$is_valid = true;
|
$is_valid = true;
|
||||||
if (!empty($properties[ 'file_dependency' ]) &&
|
if (!empty($properties[ 'file_dependency' ]) &&
|
||||||
((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1)
|
((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1)
|
||||||
) {
|
) {
|
||||||
// check file dependencies at compiled code
|
// check file dependencies at compiled code
|
||||||
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
|
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
|
||||||
|
@@ -199,7 +199,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
$template->loadCached();
|
$template->loadCached();
|
||||||
}
|
}
|
||||||
$result = $template->cached->isCached($template);
|
$result = $template->cached->isCached($template);
|
||||||
$template->smarty->_cache[ 'isCached' ][ $template->_getTemplateId() ] = $template;
|
Smarty_Internal_Template::$isCacheTplObj[ $template->_getTemplateId() ] = $template;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -219,10 +219,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
$template->tpl_vars = $savedTplVars;
|
$template->tpl_vars = $savedTplVars;
|
||||||
$template->config_vars = $savedConfigVars;
|
$template->config_vars = $savedConfigVars;
|
||||||
} else {
|
} else {
|
||||||
if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) {
|
if (!$function && !isset(Smarty_Internal_Template::$tplObjCache[ $template->templateId ])) {
|
||||||
$template->parent = null;
|
$template->parent = null;
|
||||||
$template->tpl_vars = $template->config_vars = array();
|
$template->tpl_vars = $template->config_vars = array();
|
||||||
$smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template;
|
Smarty_Internal_Template::$tplObjCache[ $template->templateId ] = $template;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user