From c9be9cd7f9dc08789e27bc5971ce8ba1709bf22a Mon Sep 17 00:00:00 2001 From: rodneyrehm Date: Sat, 17 Sep 2011 16:29:10 +0000 Subject: [PATCH] - bugfix lock_id for file resource would create invalid filepath - bugfix resource caching did not care about file.tpl in different template_dir - added svn:ignore where necessary --- change_log.txt | 3 +- .../smarty_internal_cacheresource_file.php | 2 +- libs/sysplugins/smarty_internal_utility.php | 3 ++ libs/sysplugins/smarty_resource.php | 40 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/change_log.txt b/change_log.txt index 7ef8cb41..3c8d361a 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@ ===== Smarty 3.1 trunk ===== 17.09.2011 -- bugfix reverted resource caching as it could not detect template_dir changes +- bugfix lock_id for file resource would create invalid filepath +- bugfix resource caching did not care about file.tpl in different template_dir ===== Smarty 3.1.0 ===== 15/09/2011 diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 35b1be3a..7338469f 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -54,7 +54,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource { // create locking file name // relative file name? if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) { - $_lock_dir = getcwd().$_cache_dir; + $_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir; } else { $_lock_dir = $_cache_dir; } diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index c1b968c0..d52f6056 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -234,6 +234,9 @@ class Smarty_Internal_Utility { } } } + // clear compiled cache + Smarty_Resource::$sources = array(); + Smarty_Resource::$compileds = array(); return $_count; } diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index 09fd1dee..852939e3 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -16,6 +16,16 @@ * @subpackage TemplateResources */ abstract class Smarty_Resource { + /** + * cache for Smarty_Template_Source instances + * @var array + */ + public static $sources = array(); + /** + * cache for Smarty_Template_Compiled instances + * @var array + */ + public static $compileds = array(); /** * cache for Smarty_Resource instances * @var array @@ -309,6 +319,11 @@ abstract class Smarty_Resource { */ public static function load(Smarty $smarty, $resource_type) { + // try the instance cache + if (isset(self::$resources[$resource_type])) { + return self::$resources[$resource_type]; + } + // try registered resource if (isset($smarty->registered_resources[$resource_type])) { if ($smarty->registered_resources[$resource_type] instanceof Smarty_Resource) { @@ -378,6 +393,16 @@ abstract class Smarty_Resource { $template_resource = $_template->template_resource; } + // check runtime cache + $_cache_key_dir = join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()); + $_cache_key = 'template|' . $template_resource; + if (!isset(self::$sources[$_cache_key_dir])) { + self::$sources[$_cache_key_dir] = array(); + } + if (isset(self::$sources[$_cache_key_dir][$_cache_key])) { + return self::$sources[$_cache_key_dir][$_cache_key]; + } + if (($pos = strpos($template_resource, ':')) === false) { // no resource given, use default $resource_type = $smarty->default_resource_type; @@ -397,6 +422,8 @@ abstract class Smarty_Resource { $source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name); $resource->populate($source, $_template); + // runtime cache + self::$sources[$_cache_key_dir][$_cache_key] = $source; return $source; } @@ -565,11 +592,24 @@ class Smarty_Template_Source { */ public function getCompiled(Smarty_Internal_Template $_template) { + // check runtime cache + $_cache_key_dir = join(DIRECTORY_SEPARATOR, $_template->smarty->getTemplateDir()); + $_cache_key = $_template->template_resource . '#' . $_template->compile_id; + if (!isset(Smarty_Resource::$compileds[$_cache_key_dir])) { + Smarty_Resource::$compileds[$_cache_key_dir] = array(); + } + if (isset(Smarty_Resource::$compileds[$_cache_key_dir][$_cache_key])) { + return Smarty_Resource::$compileds[$_cache_key_dir][$_cache_key]; + } + $compiled = new Smarty_Template_Compiled($this); $this->handler->populateCompiledFilepath($compiled, $_template); $compiled->timestamp = @filemtime($compiled->filepath); $compiled->exists = !!$compiled->timestamp; + // runtime cache + Smarty_Resource::$compileds[$_cache_key_dir][$_cache_key] = $compiled; + return $compiled; }