From 476f45413a9f2132788ccbbb090401d049d38942 Mon Sep 17 00:00:00 2001 From: mohrt Date: Thu, 1 Feb 2001 21:09:17 +0000 Subject: [PATCH] update caching logic --- Smarty.class.php | 28 ++++++++++++++++++++++++++++ libs/Smarty.class.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/Smarty.class.php b/Smarty.class.php index 33f78fdd..414b29cc 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -168,6 +168,34 @@ class Smarty unset($this->_tpl_vars[$tpl_var]); } +/*======================================================================*\ + Function: clear_cache() + Purpose: clear all cached template files for given template +\*======================================================================*/ + + function clear_cache($tpl_file) + { + if(is_dir($this->cache_dir)) + $dir_handle = opendir($this->cache_dir); + else + return false; + + // remove leading . or / + $tpl_file = preg_replace("/^(\.{0,2}\/)*/","",$tpl_file); + $tpl_file_url = urlencode($tpl_file); + + while($curr_file = readdir($dir_handle)) { + if ($curr_file == '.' || $curr_file == '..') + continue; + + if(is_file($this->cache_dir."/".$curr_file) && + substr($curr_file,0,strlen($tpl_file_url)) == $tpl_file_url) + unlink($this->cache_dir."/".$curr_file); + } + return true; + } + + /*======================================================================*\ Function: clear_all_cache() Purpose: clear all the cached template files. diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 33f78fdd..414b29cc 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -168,6 +168,34 @@ class Smarty unset($this->_tpl_vars[$tpl_var]); } +/*======================================================================*\ + Function: clear_cache() + Purpose: clear all cached template files for given template +\*======================================================================*/ + + function clear_cache($tpl_file) + { + if(is_dir($this->cache_dir)) + $dir_handle = opendir($this->cache_dir); + else + return false; + + // remove leading . or / + $tpl_file = preg_replace("/^(\.{0,2}\/)*/","",$tpl_file); + $tpl_file_url = urlencode($tpl_file); + + while($curr_file = readdir($dir_handle)) { + if ($curr_file == '.' || $curr_file == '..') + continue; + + if(is_file($this->cache_dir."/".$curr_file) && + substr($curr_file,0,strlen($tpl_file_url)) == $tpl_file_url) + unlink($this->cache_dir."/".$curr_file); + } + return true; + } + + /*======================================================================*\ Function: clear_all_cache() Purpose: clear all the cached template files.