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);