缓存支持设置complex类型 支持配置多种缓存并用store切换

This commit is contained in:
thinkphp
2016-08-18 08:38:41 +08:00
parent 1aea75468d
commit 3248ebd6be

View File

@@ -31,7 +31,7 @@ class Cache
* @access public
* @param array $options 配置数组
* @param bool|string $name 缓存连接标识 true 强制重新连接
* @return object
* @return \think\cache\Driver
*/
public static function connect(array $options = [], $name = false)
{
@@ -65,10 +65,30 @@ class Cache
{
if (is_null(self::$handler)) {
// 自动初始化缓存
self::connect($options ?: Config::get('cache'));
if (!empty($options)) {
self::connect($options);
} elseif ('complex' == Config::get('cache.type')) {
self::connect(Config::get('cache.default'));
} else {
self::connect(Config::get('cache'));
}
}
}
/**
* 切换缓存类型 需要配置 cache.type 为 complex
* @access public
* @param string $name 缓存标识
* @return \think\cache\Driver
*/
public static function store($name)
{
if ('complex' == Config::get('cache.type')) {
self::connect(Config::get('cache.' . $name), strtolower($name));
}
return self::$handler;
}
/**
* 判断缓存是否存在
* @access public