mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
缓存支持设置complex类型 支持配置多种缓存并用store切换
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user