Cache类tag方法增加是否覆盖参数

This commit is contained in:
thinkphp
2016-08-17 19:16:10 +08:00
parent 90fc917b00
commit fd058ab9b4
2 changed files with 15 additions and 9 deletions

View File

@@ -168,14 +168,15 @@ class Cache
/** /**
* 缓存标签 * 缓存标签
* @access public * @access public
* @param string $name 标签名 * @param string $name 标签名
* @param string|array $keys 缓存标识 * @param string|array $keys 缓存标识
* @param bool $overlay 是否覆盖
* @return \think\cache\Driver * @return \think\cache\Driver
*/ */
public static function tag($name, $keys = null) public static function tag($name, $keys = null, $overlay = false)
{ {
self::init(); self::init();
return self::$handler->tag($name, $keys); return self::$handler->tag($name, $keys, $overlay);
} }
} }

View File

@@ -94,11 +94,12 @@ abstract class Driver
/** /**
* 缓存标签 * 缓存标签
* @access public * @access public
* @param string $name 标签名 * @param string $name 标签名
* @param string|array $keys 缓存标识 * @param string|array $keys 缓存标识
* @param bool $overlay 是否覆盖
* @return $this * @return $this
*/ */
public function tag($name, $keys = null) public function tag($name, $keys = null, $overlay = false)
{ {
if (is_null($keys)) { if (is_null($keys)) {
$this->tag = $name; $this->tag = $name;
@@ -107,8 +108,12 @@ abstract class Driver
if (is_string($keys)) { if (is_string($keys)) {
$keys = explode(',', $keys); $keys = explode(',', $keys);
} }
$keys = array_map([$this, 'getCacheKey'], $keys); $keys = array_map([$this, 'getCacheKey'], $keys);
$value = array_unique(array_merge($this->getTagItem($name), $keys)); if ($overlay) {
$value = $keys;
} else {
$value = array_unique(array_merge($this->getTagItem($name), $keys));
}
$this->set($key, implode(',', $value)); $this->set($key, implode(',', $value));
} }
return $this; return $this;