我想实现在php服务器端,设置一个即使文件修改也不过期的文件。
if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == filemtime($fn))) {
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fn)).' GMT', true, 304);
} else {
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fn)).' GMT', true, 200);
header('Content-Length: '.filesize($fn));
header("Cache-Control: max-age=100000");
header("Expires: Sat, 26 Jul 2019 05:00:00 GMT"); // Date in the past
$content=file_get_contents($fn);
echo $content;
}
header("Cache-Control: max-age=100000");
header("Expires: Sat, 26 Jul 2019 05:00:00 GMT");
这两个我已经设置了足够不过期的情况,按道理说浏览器会认为到期时间没到,就不会重新像服务器请求。
(请忽略我的if段,)
我这个问题类似https://segmentfault.com/q/10...这里的问题。
基于什么语言实现不一致?
我的观点是:只要文件更改,或者etag更改,所有的cache-control:max-age,包括expires 都会失效,对吗??
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
请移步:HTTP CACHE 中的ETAG,LAST_MODIFY,MAX-AGE实验
参考问题:php设置cache-control失效
可以知道,缓存的有效与否是经过服务器判定的,在经过缓存时,会进行新鲜度检查,也就是IF首部等,若服务器返回没有改变,则使用缓存,否则每次都是新的报文
也就是说,就算你的文件改变,如果你服务器发送了304给客户端,客户端也会使用缓存进行显示.