diff --git a/library/think/Request.php b/library/think/Request.php index 8a354633..45b65423 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1486,6 +1486,12 @@ class Request public function cache($key, $expire = null) { if (false !== $key && $this->isGet() && !$this->isCheckCache) { + // 标记请求缓存检查 + $this->isCheckCache = true; + if (false === $expire) { + // 关闭当前缓存 + return; + } if ($key instanceof \Closure) { $key = call_user_func_array($key, [$this]); } elseif (true === $key) { @@ -1518,9 +1524,6 @@ class Request $key = $fun($key); } - // 标记请求缓存检查 - $this->isCheckCache = true; - if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) { // 读取缓存 $response = Response::create()->code(304); diff --git a/library/think/Route.php b/library/think/Route.php index 63cbe9c4..c8eb24e6 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1491,7 +1491,7 @@ class Route $result = self::parseModule($route); } // 开启请求缓存 - if ($request->isGet() && !empty($option['cache'])) { + if ($request->isGet() && isset($option['cache'])) { $cache = $option['cache']; if (is_array($cache)) { list($key, $expire) = $cache;