在http响应中没有Cache-Control标头的ETag [英] ETag with no Cache-Control header in http response

查看:110
本文介绍了在http响应中没有Cache-Control标头的ETag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习有关HTTP的一些基础知识.我检查了一些HTTP响应标头,发现使我感到困惑的两件事:

I am trying to learn some basics about HTTP. I've inspected a some HTTP response headers and noticed 2 things that confused me:

  • 没有缓存控制标头,并且

  • There was no cache-control header and

ETag标头存在.

我理解ETag的方式是,客户端将请求中的ETag发送到缓存,然后缓存通过服务器重新验证资源Etag.但是,如果没有响应的Cache-Control标头,则所有后续请求都直接与服务器进行重新验证,并完全省略缓存.是这种情况还是我错过了什么?当没有缓存控制标头作为响应时,还会发生其他事情吗?如果所有请求无论如何都会直接发送到服务器,为什么还会显示ETag?

The way I understood ETag is that, client sends ETag in a requests to a cache, and cache revalidates resources Etag with the server. But if there is no Cache-Control header in response, than all subsequent requests do the revalidation directly with the server and completely omit cache. Is this the case or am I missing something? Does something else happen when there is no cache-control header present in response? Why is ETag even present if all request will go to the server directly anyway?

推荐答案

缺少缓存控制标头并不意味着无法缓存资源-由客户端(即Web浏览器)决定如何处理这种不确定的状态.

The absence of a cache-control header does not mean a resource cannot be cached - it's up to the client (i.e. the web browser) to decide how to handle this undefined state.

对它进行缓存(无论是在内存中还是在磁盘中),并且只有在ETag验证的情况下才使用该缓存版本对我来说似乎是一个非常合理的实现.

Caching it (whether in memory or in disk) and only using that cached version if ETag validates seems a perfectly reasonable implementation to me.

如果您不希望缓存资源,则应使用"max-age = 0,不存储,不缓存,必须重新验证"的缓存控制标头明确地说明这一点.

If you don't want a resource cached then you should explicitly say this with a cache-control header of "max-age=0, no-store, no-cache, must-revalidate".

这篇关于在http响应中没有Cache-Control标头的ETag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆