出于某种原因,Laravel 似乎在最后一刻操纵了响应标头“Cache-Control”。我想让浏览器缓存成为可能。
class TestController extends Controller
{
public function getTest()
{
$response = new \Illuminate\Http\Response('test', 200, array(
'Cache-Control' => 'max-age='.(config('imagecache.lifetime')*60).', public',
'Content-Length' => strlen('test'),
));
$response->setLastModified(new \DateTime('now'));
$response->setExpires(\Carbon\Carbon::now()->addMinutes(config('imagecache.lifetime')));
return $response;
}
}
即使我使用“后中间件”并死掉并转储响应,我仍然会得到这个,这对我来说似乎是正确的。
Response {#625 ▼
+original: "test"
+exception: null
+headers: ResponseHeaderBag {#626 ▼
#computedCacheControl: array:2 [▼
"max-age" => "2592000"
"public" => true
]
#cookies: []
#headerNames: array:5 [▶]
#headers: array:5 [▼
"cache-control" => array:1 [▼
0 => "max-age=2592000, public"
]
"content-length" => array:1 [▼
0 => 4
]
"date" => array:1 [▶]
"last-modified" => array:1 [▼
0 => "Sun, 16 Aug 2015 15:42:08 GMT"
]
"expires" => array:1 [▶]
]
#cacheControl: array:2 [▼
"max-age" => "2592000"
"public" => true
]
}
#content: "test"
#version: "1.0"
#statusCode: 200
#statusText: "OK"
#charset: null
}
$response->isCacheable() 方法也返回 true。但是当我收到响应时,Firebug 显示以下内容:
Cache-Control
no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection
Keep-Alive
Content-Type
text/html
Date
Sun, 16 Aug 2015 15:42:08 GMT
Expires
Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive
timeout=5, max=98
Pragma
no-cache
Server
Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15
Transfer-Encoding
chunked
X-Powered-By
PHP/5.5.15
我使用 xampp,但在同一台服务器上,当我只加载一个 html 页面(没有 Laravel/PHP)时,它不会发送这些 Cache-Control 标头。
当我设置 last-modified 和 expires 标头时,如何实现浏览器不接收 Cache-Control 标头“no-store, no-cache”?
谢谢!