diff --git a/library/think/Cache.php b/library/think/Cache.php index ebdd2d4d..9f7a569d 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -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