mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进请求缓存
This commit is contained in:
@@ -103,6 +103,16 @@ class Response
|
|||||||
Debug::inject($this, $data);
|
Debug::inject($this, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (200 == $this->code) {
|
||||||
|
$cache = Request::instance()->getCache();
|
||||||
|
if ($cache) {
|
||||||
|
$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['Expires'] = gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $cache[1]) . ' GMT';
|
||||||
|
Cache::set($cache[0], [$data, $this->header], $cache[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!headers_sent() && !empty($this->header)) {
|
if (!headers_sent() && !empty($this->header)) {
|
||||||
// 发送状态码
|
// 发送状态码
|
||||||
http_response_code($this->code);
|
http_response_code($this->code);
|
||||||
@@ -111,16 +121,7 @@ class Response
|
|||||||
header($name . ':' . $val);
|
header($name . ':' . $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (200 == $this->code) {
|
|
||||||
$cache = Request::instance()->getCache();
|
|
||||||
if ($cache) {
|
|
||||||
header('Cache-Control: max-age=' . $cache[1] . ',must-revalidate');
|
|
||||||
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;
|
echo $data;
|
||||||
|
|
||||||
if (function_exists('fastcgi_finish_request')) {
|
if (function_exists('fastcgi_finish_request')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user