mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
改进请求缓存支持
This commit is contained in:
@@ -1495,12 +1495,14 @@ class Request
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Cache::has($key)) {
|
|
||||||
|
if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) {
|
||||||
// 读取缓存
|
// 读取缓存
|
||||||
$content = Cache::get($key);
|
$response = Response::create()->code(304);
|
||||||
$response = Response::create($content)
|
throw new \think\exception\HttpResponseException($response);
|
||||||
->code(304)
|
} elseif (Cache::has($key)) {
|
||||||
->header('Content-Type', Cache::get($key . '_header'));
|
list($content, $header) = Cache::get($key);
|
||||||
|
$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];
|
||||||
|
|||||||
@@ -111,15 +111,17 @@ class Response
|
|||||||
header($name . ':' . $val);
|
header($name . ':' . $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo $data;
|
|
||||||
|
|
||||||
if (200 == $this->code) {
|
if (200 == $this->code) {
|
||||||
$cache = Request::instance()->getCache();
|
$cache = Request::instance()->getCache();
|
||||||
if ($cache) {
|
if ($cache) {
|
||||||
Cache::set($cache[0], $data, $cache[1]);
|
header('Cache-Control: max-age=' . $cache[1] . ',must-revalidate');
|
||||||
Cache::set($cache[0] . '_header', $this->header['Content-Type']);
|
header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
|
header('Expires:' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $cache[1]) . ' GMT');
|
||||||
|
$header['Content-Type'] = $this->header['Content-Type'];
|
||||||
|
Cache::set($cache[0], [$data, $header], $cache[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
echo $data;
|
||||||
|
|
||||||
if (function_exists('fastcgi_finish_request')) {
|
if (function_exists('fastcgi_finish_request')) {
|
||||||
// 提高页面响应
|
// 提高页面响应
|
||||||
|
|||||||
Reference in New Issue
Block a user