请求缓存的有效期如果传入false表示不缓存 路由规则的cache参数传入false也同样表示不缓存 即使开启了全局请求缓存

This commit is contained in:
thinkphp
2016-11-09 13:53:36 +08:00
parent 53329b79b6
commit 7eaf95de9b
2 changed files with 7 additions and 4 deletions

View File

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

View File

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