- 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
This commit is contained in:
rodneyrehm
2011-09-17 16:29:10 +00:00
parent 00d45f4d3f
commit c9be9cd7f9
4 changed files with 46 additions and 2 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -234,6 +234,9 @@ class Smarty_Internal_Utility {
}
}
}
// clear compiled cache
Smarty_Resource::$sources = array();
Smarty_Resource::$compileds = array();
return $_count;
}

View File

@@ -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;
}