mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
请求缓存的有效期如果传入false表示不缓存 路由规则的cache参数传入false也同样表示不缓存 即使开启了全局请求缓存
This commit is contained in:
@@ -1486,6 +1486,12 @@ class Request
|
|||||||
public function cache($key, $expire = null)
|
public function cache($key, $expire = null)
|
||||||
{
|
{
|
||||||
if (false !== $key && $this->isGet() && !$this->isCheckCache) {
|
if (false !== $key && $this->isGet() && !$this->isCheckCache) {
|
||||||
|
// 标记请求缓存检查
|
||||||
|
$this->isCheckCache = true;
|
||||||
|
if (false === $expire) {
|
||||||
|
// 关闭当前缓存
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ($key instanceof \Closure) {
|
if ($key instanceof \Closure) {
|
||||||
$key = call_user_func_array($key, [$this]);
|
$key = call_user_func_array($key, [$this]);
|
||||||
} elseif (true === $key) {
|
} elseif (true === $key) {
|
||||||
@@ -1518,9 +1524,6 @@ class Request
|
|||||||
$key = $fun($key);
|
$key = $fun($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 标记请求缓存检查
|
|
||||||
$this->isCheckCache = true;
|
|
||||||
|
|
||||||
if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) {
|
if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) {
|
||||||
// 读取缓存
|
// 读取缓存
|
||||||
$response = Response::create()->code(304);
|
$response = Response::create()->code(304);
|
||||||
|
|||||||
@@ -1491,7 +1491,7 @@ class Route
|
|||||||
$result = self::parseModule($route);
|
$result = self::parseModule($route);
|
||||||
}
|
}
|
||||||
// 开启请求缓存
|
// 开启请求缓存
|
||||||
if ($request->isGet() && !empty($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) = $cache;
|
||||||
|
|||||||
Reference in New Issue
Block a user