- bugfix Smarty_Resource and Smarty_CacheResource runtime caching (Forum Post 75264)

www.smarty.net/forums/viewtopic.php?p=75264#75264
This commit is contained in:
rodneyrehm
2011-10-15 10:46:03 +00:00
parent 318328cd75
commit 131553272a
4 changed files with 69 additions and 36 deletions
+17 -10
View File
@@ -18,14 +18,14 @@ abstract class Smarty_CacheResource {
* cache for Smarty_CacheResource instances
* @var array
*/
protected static $resources = array();
public static $resources = array();
/**
* resource types provided by the core
* @var array
*/
protected static $sysplugins = array(
'file' => true,
'file' => true,
);
/**
@@ -148,25 +148,32 @@ abstract class Smarty_CacheResource {
if (!isset($type)) {
$type = $smarty->caching_type;
}
// try the instance cache
if (isset(self::$resources[$type])) {
// FIXME: rodneyrehm need to validate if cache resource may be used in given $smarty.
return self::$resources[$type];
// try smarty's cache
if (isset($smarty->_cacheresource_handlers[$type])) {
return $smarty->_cacheresource_handlers[$type];
}
// try registered resource
if (isset($smarty->registered_cache_resources[$type])) {
// do not cache these instances as they may vary from instance to instance
return $smarty->registered_cache_resources[$type];
return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
}
// try sysplugins dir
if (isset(self::$sysplugins[$type])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
return self::$resources[$type] = new $cache_resource_class();
if (!isset(self::$resources[$type])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
self::$resources[$type] = new $cache_resource_class();
}
return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
}
// try plugins dir
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
if ($smarty->loadPlugin($cache_resource_class)) {
return self::$resources[$type] = new $cache_resource_class();
if (!isset(self::$resources[$type])) {
self::$resources[$type] = new $cache_resource_class();
}
return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
}
// give up
throw new SmartyException("Unable to load cache resource '{$type}'");