From 0e4549fe768c1df227ef1404854fa05e3fffa544 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 3 Sep 2016 21:41:33 +0800 Subject: [PATCH] =?UTF-8?q?Query=E7=B1=BBcache=E6=96=B9=E6=B3=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=AC=AC=E4=B8=89=E4=B8=AA=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E7=BC=93=E5=AD=98=E6=A0=87?= =?UTF-8?q?=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 10ed25b1..838f7ac3 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -403,7 +403,11 @@ class Query $result = $pdo->fetchColumn(); if (isset($cache)) { // 缓存数据 - Cache::set($key, $result, $cache['expire']); + if (isset($cache['tag'])) { + Cache::tag($cache['tag'])->set($key, $result, $cache['expire']); + } else { + Cache::set($key, $result, $cache['expire']); + } } } else { // 清空查询条件 @@ -468,7 +472,11 @@ class Query } if (isset($cache) && isset($guid)) { // 缓存数据 - Cache::set($guid, $result, $cache['expire']); + if (isset($cache['tag'])) { + Cache::tag($cache['tag'])->set($guid, $result, $cache['expire']); + } else { + Cache::set($guid, $result, $cache['expire']); + } } } else { // 清空查询条件 @@ -1067,9 +1075,10 @@ class Query * @access public * @param mixed $key 缓存key * @param integer $expire 缓存有效期 + * @param string $tag 缓存标签 * @return $this */ - public function cache($key = true, $expire = null) + public function cache($key = true, $expire = null, $tag = null) { // 增加快捷调用方式 cache(10) 等同于 cache(true, 10) if (is_numeric($key) && is_null($expire)) { @@ -1077,7 +1086,7 @@ class Query $key = true; } if (false !== $key) { - $this->options['cache'] = ['key' => $key, 'expire' => $expire]; + $this->options['cache'] = ['key' => $key, 'expire' => $expire, 'tag' => $tag]; } return $this; } @@ -1881,7 +1890,11 @@ class Query if (isset($cache)) { // 缓存数据集 - Cache::set($key, $resultSet, $cache['expire']); + if (isset($cache['tag'])) { + Cache::tag($cache['tag'])->set($key, $resultSet, $cache['expire']); + } else { + Cache::set($key, $resultSet, $cache['expire']); + } } } @@ -1968,7 +1981,11 @@ class Query if (isset($cache)) { // 缓存数据 - Cache::set($key, $result, $cache['expire']); + if (isset($cache['tag'])) { + Cache::tag($cache['tag'])->set($key, $result, $cache['expire']); + } else { + Cache::set($key, $result, $cache['expire']); + } } }