var epoch = time.Unix(0, 0).Format(time.RFC1123)
var headers = map[string]string{
"Expires": epoch,
"Cache-Control": "no-cache, private, max-age=0",
"Pragma": "no-cache",
"X-Accel-Expires": "0",
}
log.Errorln("no cache header")
for k, v := range headers {
rw.Header().Set(k, v)
}
http.ServeFile(rw, req, path)
我在服务器端有上面的代码块来处理文件请求。但是所提供的文件仍然在浏览器中缓存。
但我使用http.ServeFile()
代替http.ServeContent()
,最后修改时间戳为time.Now()
。如果请求有相当大的时间差异,则此方法有效浏览器是否优先考虑上次修改时间而不是no-cache
标题?那么no-cache
标题的目的是什么?我做错了吗?
答案 0 :(得分:0)
有些浏览器会在不注意标题的情况下缓存文件。典型的解决方案是在静态文件路径中添加一些get参数,因此浏览器将其视为不同的请求。它可以是哈希值或上次修改的时间戳。它可能看起来像这样:NSOperationQueue
。