mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- optimize invalidation of internal caches
This commit is contained in:
@@ -216,12 +216,13 @@ abstract class Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
*/
|
||||
public static function invalidLoadedCache(Smarty $smarty)
|
||||
public function invalidLoadedCache(Smarty $smarty)
|
||||
{
|
||||
foreach ($smarty->_cache['template_objects'] as $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
$tpl->cached->valid = false;
|
||||
$tpl->cached->processed = false;
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
unset ($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -209,20 +209,18 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
$cache_name = null;
|
||||
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = true;
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
$smarty->caching = $_save_stat;
|
||||
|
||||
if ($tpl->source->exists) {
|
||||
$cache_name = $tpl->source->name;
|
||||
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
|
||||
if ($source->exists) {
|
||||
$cache_name = $source->name;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
// remove from template cache
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $_tpl) {
|
||||
if (isset($_tpl->cached) && $_tpl->source->uid == $tpl->source->uid) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $_tpl) {
|
||||
if (isset($_tpl->cached) && $_tpl->source->uid == $source->uid) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -165,9 +165,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$this->invalidate(null);
|
||||
}
|
||||
// remove from template cache
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return - 1;
|
||||
@@ -196,9 +198,13 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$this->delete(array($cid));
|
||||
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
|
||||
// remove from template cache
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if ($tpl->source->uid == $uid && isset($tpl->cached)) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
if (isset($resource_name) && isset($smarty->_cache['template_objects'])) {
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if ($tpl->source->uid == $uid && isset($tpl->cached)) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return - 1;
|
||||
@@ -217,7 +223,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
protected function getTemplateUid(Smarty $smarty, $resource_name)
|
||||
{
|
||||
if (isset($resource_name)) {
|
||||
$source = new Smarty_Template_Source(null, $smarty, $resource_name);
|
||||
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
|
||||
if ($source->exists) {
|
||||
return $source->uid;
|
||||
}
|
||||
|
@@ -112,9 +112,11 @@ class Smarty_Internal_Extension_Clear
|
||||
}
|
||||
}
|
||||
// remove from template cache
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached) && $tpl->cached->filepath == $_file) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached) && $tpl->cached->filepath == (string)$_file) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$_count += @unlink((string) $_file) ? 1 : 0;
|
||||
|
@@ -34,7 +34,9 @@ class Smarty_Internal_Method_ClearAllCache
|
||||
{
|
||||
// load cache resource and call clearAll
|
||||
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
|
||||
Smarty_CacheResource::invalidLoadedCache($smarty);
|
||||
if ($smarty->caching_type != 'file') {
|
||||
$_cache_resource->invalidLoadedCache($smarty);
|
||||
}
|
||||
|
||||
return $_cache_resource->clearAll($smarty, $exp_time);
|
||||
}
|
||||
|
@@ -37,7 +37,9 @@ class Smarty_Internal_Method_ClearCache
|
||||
{
|
||||
// load cache resource and call clear
|
||||
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
|
||||
Smarty_CacheResource::invalidLoadedCache($smarty);
|
||||
if ($smarty->caching_type != 'file' && !isset($template_name)) {
|
||||
$_cache_resource->invalidLoadedCache($smarty);
|
||||
}
|
||||
|
||||
return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
@@ -49,11 +49,6 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
if ($tpl->source->exists) {
|
||||
// remove from compileds cache
|
||||
$tpl->source->compileds = array();
|
||||
// remove from template cache
|
||||
$_templateId = $tpl->smarty->_getTemplateId($resource_name);
|
||||
if (isset($smarty->_cache['template_objects'][$_templateId])) {
|
||||
unset($smarty->_cache['template_objects'][$_templateId]);
|
||||
}
|
||||
$_resource_part_1 = basename(str_replace('^', DS, $tpl->compiled->filepath));
|
||||
$_resource_part_1_length = strlen($_resource_part_1);
|
||||
} else {
|
||||
@@ -111,6 +106,13 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
}
|
||||
|
||||
if ($unlink && @unlink($_filepath)) {
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->compiled) && $tpl->compiled->filepath == $_filepath) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$_count ++;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user