mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
请求缓存支持缓存标签设置
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
4
library/think/cache/Driver.php
vendored
4
library/think/cache/Driver.php
vendored
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user