From a77f702a9f802d8424139fe8e325e87938021d4c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 17 Aug 2016 16:34:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BCache=E7=B1=BB=E7=9A=84tag?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=9A=84=E7=BC=93=E5=AD=98=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 5 +++-- library/think/cache/Driver.php | 13 ++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/library/think/Cache.php b/library/think/Cache.php index a958911d..21ef59e8 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -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); } } diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index de4080c7..e1b4bcbd 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -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); + } } /**