From 4e27b70ba5f46c1645de00aa3e589d50093dd849 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Tue, 27 Apr 2010 17:47:24 +0000 Subject: [PATCH] - bugfix in $smarty->cache->clear() method. (do not cache template object) --- .../smarty_internal_cacheresource_file.php | 102 +++++++++--------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 2895d12b..6e451038 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -1,30 +1,30 @@ smarty = $smarty; } /** - * Returns the filepath of the cached template output - * - * @param object $_template current template - * @return string the cache filepath - */ + * Returns the filepath of the cached template output + * + * @param object $_template current template + * @return string the cache filepath + */ public function getCachedFilepath($_template) { $_source_file_path = str_replace(':', '.', $_template->getTemplateFilepath()); @@ -57,11 +57,11 @@ class Smarty_Internal_CacheResource_File { } /** - * Returns the timpestamp of the cached template output - * - * @param object $_template current template - * @return integer |booelan the template timestamp or false if the file does not exist - */ + * Returns the timpestamp of the cached template output + * + * @param object $_template current template + * @return integer |booelan the template timestamp or false if the file does not exist + */ public function getCachedTimestamp($_template) { // return @filemtime ($_template->getCachedFilepath()); @@ -69,11 +69,11 @@ class Smarty_Internal_CacheResource_File { } /** - * Returns the cached template output - * - * @param object $_template current template - * @return string |booelan the template content or false if the file does not exist - */ + * Returns the cached template output + * + * @param object $_template current template + * @return string |booelan the template content or false if the file does not exist + */ public function getCachedContents($_template) { ob_start(); @@ -83,11 +83,11 @@ class Smarty_Internal_CacheResource_File { } /** - * Writes the rendered template output to cache file - * - * @param object $_template current template - * @return boolean status - */ + * Writes the rendered template output to cache file + * + * @param object $_template current template + * @return boolean status + */ public function writeCachedContent($_template, $content) { if (!$_template->resource_object->isEvaluated) { @@ -100,24 +100,24 @@ class Smarty_Internal_CacheResource_File { } /** - * Empty cache folder - * - * @param integer $exp_time expiration time - * @return integer number of cache files deleted - */ + * Empty cache folder + * + * @param integer $exp_time expiration time + * @return integer number of cache files deleted + */ public function clearAll($exp_time = null) { return $this->clear(null, null, null, $exp_time); } /** - * Empty cache for a specific template - * - * @param string $resource_name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @param integer $exp_time expiration time - * @return integer number of cache files deleted - */ + * Empty cache for a specific template + * + * @param string $resource_name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @return integer number of cache files deleted + */ public function clear($resource_name, $cache_id, $compile_id, $exp_time) { $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null; @@ -131,12 +131,14 @@ class Smarty_Internal_CacheResource_File { $_cache_id_parts_count = count($_cache_id_parts); } if (isset($resource_name)) { - $_save_stat = $this->smarty->caching; - $this->smarty->caching = true; - $tpl = $this->smarty->createTemplate($resource_name); - $this->smarty->caching = $_save_stat; + $_save_stat = $this->smarty->caching; + $this->smarty->caching = true; + $tpl = new $this->smarty->template_class($resource_name, $this->smarty); + // remove from template cache + unset($this->smarty->template_objects[crc32($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]); + $this->smarty->caching = $_save_stat; if ($tpl->isExisting()) { - $_resourcename_parts = basename(str_replace('^','/',$tpl->getCachedFilepath())); + $_resourcename_parts = basename(str_replace('^', '/', $tpl->getCachedFilepath())); } else { return 0; } @@ -179,7 +181,7 @@ class Smarty_Internal_CacheResource_File { // expired ? if (isset($exp_time) && time() - @filemtime($_file) < $exp_time) { continue; - } + } $_count += @unlink((string) $_file) ? 1 : 0; } }