mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
请求缓存支持缓存标签设置
This commit is contained in:
@@ -1534,10 +1534,16 @@ class Request
|
|||||||
* @param string $key 缓存标识,支持变量规则 ,例如 item/:name/:id
|
* @param string $key 缓存标识,支持变量规则 ,例如 item/:name/:id
|
||||||
* @param mixed $expire 缓存有效期
|
* @param mixed $expire 缓存有效期
|
||||||
* @param array $except 缓存排除
|
* @param array $except 缓存排除
|
||||||
|
* @param string $tag 缓存标签
|
||||||
* @return void
|
* @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) {
|
if (false !== $key && $this->isGet() && !$this->isCheckCache) {
|
||||||
// 标记请求缓存检查
|
// 标记请求缓存检查
|
||||||
$this->isCheckCache = true;
|
$this->isCheckCache = true;
|
||||||
@@ -1591,7 +1597,7 @@ class Request
|
|||||||
$response = Response::create($content)->header($header);
|
$response = Response::create($content)->header($header);
|
||||||
throw new \think\exception\HttpResponseException($response);
|
throw new \think\exception\HttpResponseException($response);
|
||||||
} else {
|
} 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['Cache-Control'] = 'max-age=' . $cache[1] . ',must-revalidate';
|
||||||
$this->header['Last-Modified'] = gmdate('D, d M Y H:i:s') . ' GMT';
|
$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';
|
$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'])) {
|
if ($request->isGet() && isset($option['cache'])) {
|
||||||
$cache = $option['cache'];
|
$cache = $option['cache'];
|
||||||
if (is_array($cache)) {
|
if (is_array($cache)) {
|
||||||
list($key, $expire) = $cache;
|
list($key, $expire, $tag) = array_pad($cache, 3, null);
|
||||||
} else {
|
} else {
|
||||||
$key = str_replace('|', '/', $pathinfo);
|
$key = str_replace('|', '/', $pathinfo);
|
||||||
$expire = $cache;
|
$expire = $cache;
|
||||||
|
$tag = null;
|
||||||
}
|
}
|
||||||
$request->cache($key, $expire);
|
$request->cache($key, $expire, $tag);
|
||||||
}
|
}
|
||||||
return $result;
|
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)
|
public function tag($name, $keys = null, $overlay = false)
|
||||||
{
|
{
|
||||||
if (is_null($keys)) {
|
if (is_null($name)) {
|
||||||
|
|
||||||
|
} elseif (is_null($keys)) {
|
||||||
$this->tag = $name;
|
$this->tag = $name;
|
||||||
} else {
|
} else {
|
||||||
$key = 'tag_' . md5($name);
|
$key = 'tag_' . md5($name);
|
||||||
|
|||||||
Reference in New Issue
Block a user