From f7fd63e8901c9158efb9a4a8609603aa29ba5abb Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Mon, 21 Jun 2010 20:10:22 +0000 Subject: [PATCH] - improved speed of cache->clear() when a compile_id was specified and use_sub_dirs is true --- change_log.txt | 1 + .../smarty_internal_cacheresource_file.php | 75 ++++++++++--------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/change_log.txt b/change_log.txt index ea1d38b2..59c54369 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,6 @@ 21/06/2010 - removed use of PHP shortags SMARTY_PHP_PASSTHRU mode +- improved speed of cache->clear() when a compile_id was specified and use_sub_dirs is true 20/06/2010 - replace internal get_time() calls with standard PHP5 microtime(true) calls diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 6e451038..9ca579db 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -129,6 +129,11 @@ class Smarty_Internal_CacheResource_File { if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); $_cache_id_parts_count = count($_cache_id_parts); + if ($this->smarty->use_sub_dirs) { + foreach ($_cache_id_parts as $id_part) { + $_dir .= $id_part . DS; + } + } } if (isset($resource_name)) { $_save_stat = $this->smarty->caching; @@ -144,45 +149,47 @@ class Smarty_Internal_CacheResource_File { } } $_count = 0; - $_cacheDirs = new RecursiveDirectoryIterator($_dir); - $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); - foreach ($_cache as $_file) { - if (strpos($_file, '.svn') !== false) continue; - // directory ? - if ($_file->isDir()) { - if (!$_cache->isDot()) { - // delete folder if empty - @rmdir($_file->getPathname()); - } - } else { - $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string)$_file, $_dir_length))); - $_parts_count = count($_parts); - // check name - if (isset($resource_name)) { - if ($_parts[$_parts_count-1] != $_resourcename_parts) { + if (file_exists($_dir)) { + $_cacheDirs = new RecursiveDirectoryIterator($_dir); + $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); + foreach ($_cache as $_file) { + if (strpos($_file, '.svn') !== false) continue; + // directory ? + if ($_file->isDir()) { + if (!$_cache->isDot()) { + // delete folder if empty + @rmdir($_file->getPathname()); + } + } else { + $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string)$_file, $_dir_length))); + $_parts_count = count($_parts); + // check name + if (isset($resource_name)) { + if ($_parts[$_parts_count-1] != $_resourcename_parts) { + continue; + } + } + // check compile id + if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) { continue; } - } - // check compile id - if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) { - continue; - } - // check cache id - if (isset($_cache_id)) { - // count of cache id parts - $_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; - if ($_parts_count < $_cache_id_parts_count) { + // check cache id + if (isset($_cache_id)) { + // count of cache id parts + $_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; + if ($_parts_count < $_cache_id_parts_count) { + continue; + } + for ($i = 0; $i < $_cache_id_parts_count; $i++) { + if ($_parts[$i] != $_cache_id_parts[$i]) continue 2; + } + } + // expired ? + if (isset($exp_time) && time() - @filemtime($_file) < $exp_time) { continue; } - for ($i = 0; $i < $_cache_id_parts_count; $i++) { - if ($_parts[$i] != $_cache_id_parts[$i]) continue 2; - } + $_count += @unlink((string) $_file) ? 1 : 0; } - // expired ? - if (isset($exp_time) && time() - @filemtime($_file) < $exp_time) { - continue; - } - $_count += @unlink((string) $_file) ? 1 : 0; } } return $_count;