Query类cache方法增加第三个参数 用于设置缓存标签

This commit is contained in:
thinkphp
2016-09-03 21:41:33 +08:00
parent 26146d06f5
commit 0e4549fe76

View File

@@ -403,7 +403,11 @@ class Query
$result = $pdo->fetchColumn(); $result = $pdo->fetchColumn();
if (isset($cache)) { 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 { } else {
// 清空查询条件 // 清空查询条件
@@ -468,7 +472,11 @@ class Query
} }
if (isset($cache) && isset($guid)) { 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 { } else {
// 清空查询条件 // 清空查询条件
@@ -1067,9 +1075,10 @@ class Query
* @access public * @access public
* @param mixed $key 缓存key * @param mixed $key 缓存key
* @param integer $expire 缓存有效期 * @param integer $expire 缓存有效期
* @param string $tag 缓存标签
* @return $this * @return $this
*/ */
public function cache($key = true, $expire = null) public function cache($key = true, $expire = null, $tag = null)
{ {
// 增加快捷调用方式 cache(10) 等同于 cache(true, 10) // 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
if (is_numeric($key) && is_null($expire)) { if (is_numeric($key) && is_null($expire)) {
@@ -1077,7 +1086,7 @@ class Query
$key = true; $key = true;
} }
if (false !== $key) { if (false !== $key) {
$this->options['cache'] = ['key' => $key, 'expire' => $expire]; $this->options['cache'] = ['key' => $key, 'expire' => $expire, 'tag' => $tag];
} }
return $this; return $this;
} }
@@ -1881,7 +1890,11 @@ class Query
if (isset($cache)) { 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)) { 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']);
}
} }
} }