From fd058ab9b43d6ed51ac643a2b429883a2a5ffda1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 17 Aug 2016 19:16:10 +0800 Subject: [PATCH] =?UTF-8?q?Cache=E7=B1=BBtag=E6=96=B9=E6=B3=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=98=AF=E5=90=A6=E8=A6=86=E7=9B=96=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 9 +++++---- library/think/cache/Driver.php | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/library/think/Cache.php b/library/think/Cache.php index 21ef59e8..ebdd2d4d 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -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); } } diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index b975ba0d..021ae727 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -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;