From 3248ebd6bea64d6afbae2bdbca163810608f86ac Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 18 Aug 2016 08:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEcomplex=E7=B1=BB=E5=9E=8B=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=A4=9A=E7=A7=8D=E7=BC=93=E5=AD=98=E5=B9=B6?= =?UTF-8?q?=E7=94=A8store=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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