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