From 5d80302da50da920d93127c3f403b3dde3194f86 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 17 Aug 2017 14:22:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=BC=93=E5=AD=98=E6=A0=87=E7=AD=BE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 10 ++++++++-- library/think/Response.php | 2 +- library/think/Route.php | 5 +++-- library/think/cache/Driver.php | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index ab79858c..36b2ac2d 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1534,10 +1534,16 @@ class Request * @param string $key 缓存标识,支持变量规则 ,例如 item/:name/:id * @param mixed $expire 缓存有效期 * @param array $except 缓存排除 + * @param string $tag 缓存标签 * @return void */ - public function cache($key, $expire = null, $except = []) + public function cache($key, $expire = null, $except = [], $tag = null) { + if (!is_array($except)) { + $tag = $except; + $except = []; + } + if (false !== $key && $this->isGet() && !$this->isCheckCache) { // 标记请求缓存检查 $this->isCheckCache = true; @@ -1591,7 +1597,7 @@ class Request $response = Response::create($content)->header($header); throw new \think\exception\HttpResponseException($response); } else { - $this->cache = [$key, $expire]; + $this->cache = [$key, $expire, $tag]; } } } diff --git a/library/think/Response.php b/library/think/Response.php index 7ae9fed7..bd30bdec 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -106,7 +106,7 @@ class Response $this->header['Cache-Control'] = 'max-age=' . $cache[1] . ',must-revalidate'; $this->header['Last-Modified'] = gmdate('D, d M Y H:i:s') . ' GMT'; $this->header['Expires'] = gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $cache[1]) . ' GMT'; - Cache::set($cache[0], [$data, $this->header], $cache[1]); + Cache::tag($cache[2])->set($cache[0], [$data, $this->header], $cache[1]); } } diff --git a/library/think/Route.php b/library/think/Route.php index 5f9f2a88..cef35c98 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1512,12 +1512,13 @@ class Route if ($request->isGet() && isset($option['cache'])) { $cache = $option['cache']; if (is_array($cache)) { - list($key, $expire) = $cache; + list($key, $expire, $tag) = array_pad($cache, 3, null); } else { $key = str_replace('|', '/', $pathinfo); $expire = $cache; + $tag = null; } - $request->cache($key, $expire); + $request->cache($key, $expire, $tag); } return $result; } diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index 775f219d..c87d8034 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -140,7 +140,9 @@ abstract class Driver */ public function tag($name, $keys = null, $overlay = false) { - if (is_null($keys)) { + if (is_null($name)) { + + } elseif (is_null($keys)) { $this->tag = $name; } else { $key = 'tag_' . md5($name);