缓存处理步骤
1 接收:读取请求报文
2 解析:解析报文,提取 url 和首部
3 查询:查询是否有本地副本可用(metadata)
4 新鲜度检测
5 创建响应
6 发送(cache-control ,age,expires,via)
7 日志
服务器配置
cache-control
: max-age=0(秒数) no-store(禁止缓存对响应进行复制)
no-cache(do-not-serve-from-cache-without-revalidation)
must-revalidate(504)expires(响应失效时间)
age
优先级
1 | cache-control:no-store -> cache-control:no-cache -> |
客户端配置
Cache-Control : no-cache
If-Modified-Since :’Mon, 26 Jul 1997 05:00:00 GMT’
pragma: no-cache
IFRAME 配置
1 | <meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT" /> |
相互影响
http 请求 | http 返回 |
---|---|
if-modified-since | expires last-modified |
if-none-match | etag(实体标记) |
最终解决方案
在前端配置
Cache-Control : no-cache
If-Modified-Since :’Mon, 26 Jul 1997 05:00:00 GMT’
pragma: no-cache服务器端配置(api 的 http get 请求 )
在服务器 response 头部添加
cache-control : max-age=0, no-cache ,must-revalidate
expires:0
或者 nginx 配置 response 头部