改进Cache类的tag方法 支持设置标签的缓存标识

This commit is contained in:
thinkphp
2016-08-17 16:34:33 +08:00
parent ea1dc1ff04
commit a77f702a9f
2 changed files with 13 additions and 5 deletions

View File

@@ -169,12 +169,13 @@ class Cache
* 缓存标签
* @access public
* @param string $name 标签名
* @param string|array $keys 缓存标识
* @return \think\cache\Driver
*/
public static function tag($name)
public static function tag($name, $keys = null)
{
self::init();
return self::$handler->tag($name);
return self::$handler->tag($name, $keys);
}
}

View File

@@ -84,12 +84,19 @@ abstract class Driver
* 缓存标签
* @access public
* @param string $name 标签名
* @param string|array $keys 缓存标识
* @return $this
*/
public function tag($name)
public function tag($name, $keys = null)
{
$this->tag = $name;
return $this;
if (is_null($keys)) {
$this->tag = $name;
return $this;
} else {
$key = 'tag_' . md5($name);
$value = is_array($keys) ? implode(',', $keys) : $keys;
$this->set($key, $value);
}
}
/**