设置缓存控制是否即使没有条件请求也不会自动启用缓存?
对于以下图像: https:// upload.wikimedia.org/wikipedia/commons/7/79/2010-brown-bear.jpg
没有任何 cache-control
标头。并且根据此处,即使您不发送任何内容,它也会使用其默认值为 private
。那不是URLSession需要执行条件请求来确保其仍然有效吗?
There isn't any cache-control
header. And based on here even if you don't send anything then it will use its default value which is private
. That being doesn't the URLSession need to perform a conditional request to make sure its still valid?
标头中是否有任何内容可以发出这样的条件请求?因为我看不到缓存控制
,最大年龄
,过期
。我唯一看到的是最后修改
& Etag
,但是它再次需要针对服务器进行验证,或者未指定任何内容使其无限期地缓存吗?我已经阅读了此答案,但是没有讨论这种情况。
Is there anything in the headers that allows it to make such a conditional request? Because I don't see cache-control
, max-age
, Expires
. The only things I see is are Last-Modified
& Etag
but again it needs to validate against the server or does not specifying anything make it cache indefinitely?! I've already read this answer, but doesn't discuss this scenario.
但是URLSession正在缓存它。 (因为如果我关闭了互联网,仍然可以下载)
Yet it's being cached by the URLSession. (Because if I turn off internet, still it gets downloaded)
我只看到的另一件事是严格的传输安全:max-年龄= 106384710
。
Only other thing I see is "Strict-Transport-Security": max-age=106384710
.
这会影响缓存吗?我已经在此处并且不相信它应该。从我的角度来看,HSTS密钥的最大年龄
仅用于强制在一定时间内从HTTPS访问它。一旦达到最大使用期限,则也可以通过HTTP访问。
Does that effect caching? I've already look here and don't believe it should. From what I the max-age
for the HSTS key is there only to enforce it to be accessed from HTTPS for a certain period of time. Once the max-age is reached then access through HTTP is also possible.
这些都是我要返回的标头:
These are all the headers that I'm getting back:
Date : Wed, 31 Oct 2018 14:15:33 GMT
Content-Length : 215104
Access-Control-Expose-Headers: Age, Date, Content-Length, Content-Range, X-Content-Duration, X-Cache, X-Varnish
Via : 1.1 varnish (Varnish/5.1), 1.1 varnish (Varnish/5.1)
Age : 18581
Etag : 00e21950bf432476c91b811bb685b6af
Strict-Transport-Security : max-age=106384710; includeSubDomains; preload
Accept-Ranges : bytes
Content-Type : image/jpeg
Last-Modified : Fri, 04 Oct 2013 23:30:08 GMT
Access-Control-Allow-Origin : *
Timing-Allow-Origin : *
x-analytics : https=1;nocookies=1
x-object-meta-sha1base36 : 42tq5grg9rq1ydmqd4z5hmmqj6h2309
x-varnish : 60926196 48388489, 342256851 317476424
x-cache-status : hit-front
x-trans-id : tx08ed43bbcc1946269a9a3-005bd97070
x-timestamp : 1380929407.39127
x-cache : cp1076 hit/7, cp1090 hit/7
x-client-ip : 2001:558:1400:4e:171:2a98:fad6:2579
由于此注释
URLSession不需要执行条件请求来确保其仍然有效吗?
doesn't the URLSession need to perform a conditional request to make sure its still valid?
由于
$,用户代理应该正在执行条件请求b $ bEtag :00e21950bf432476c91b811bb685b6af
Etag: 00e21950bf432476c91b811bb685b6af
存在。我的台式机Chrome浏览器确实会执行条件请求(并返回304未修改)。
present. My desktop Chrome certainly does performs the conditional request (and gets back 304 Not Modified).
但是用户代理完全可以自行决定。完全免费:
But a user-agent is perfectly free to decide on it's own. It's perfectly free to look at:
最后修改:星期五,2013年10月4日23:30:08 GMT
Last-Modified: Fri, 04 Oct 2013 23:30:08 GMT
并确定接下来的五分钟内 1 的资源可能是好的。并且,如果网络连接断开,则完全合理且正确地显示了缓存的版本。实际上,即使您的拨号0.00336 Mbps拨号调制解调器已断开连接,您的浏览器也会显示您的网站。
and decide that there resource is probably good for the next five minutes1. And if the network connection is down, its perfectly reasonable and correct to display the cached version instead. In fact, your browser would show you web-sites even while your dial-up 0.00336 Mbps dial-up modem was disconnected.
您不希望浏览器显示您什么也没有,只要它非常了解,它就能向您展示一些东西。当我们在谈论互联网连接质量差的原因时,它变得更加有用,这不仅是由于拨号速度慢和服务器故障所致,还在于移动计算和计量数据计划。
You wouldn't want your browser to show you nothing, when it knows full well it can show you something. It becomes even more useful when we're talking about poor internet connectivity not because of slow dialup and servers that go down, but of mobile computing, and metered data plans.
1 我说5分钟,因为在早期的Web中,服务器未提供缓存提示。因此,浏览器甚至无需询问即可缓存内容。 5分钟是一个很好的数字。然后您使用 Ctrl + F5 (或者是 Shift + F5 ,还是 Shift + Click ,或者是 Alt + Click )来强制浏览器绕过缓存。
1I say 5 minutes, because in the early web, servers did not give cache hints. So browsers cached things without even being asked. And 5 minutes was a good number. And you used Ctrl+F5 (or was it Shift+F5, or was it Shift+Click, or was it Alt+Click) to force the browser to bypass the cache.