首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何理解RFC2616在“缓存-控制机制”部分的“语义透明”?

如何理解RFC2616在“缓存-控制机制”部分的“语义透明”?
EN

Stack Overflow用户
提问于 2013-03-13 06:35:12
回答 1查看 482关注 0票数 3

1. RFC2616 "1.3术语“中”语义透明“的定义

语义透明

代码语言:javascript
复制
  A cache behaves in a "semantically transparent" manner, with
  respect to a particular response, when its use affects neither the
  requesting client nor the origin server, except to improve
  performance. When a cache is semantically transparent, the client
  receives exactly the same response (except for hop-by-hop headers)
  that it would have received had its request been handled directly
  by the origin server.

2.我无法理解RFC2616 "13.1.3缓存控制机制“的句子。

Cache-Control报头允许客户端或服务器在请求或响应中传输各种指令。这些指令通常覆盖默认的缓存算法。作为一般规则,如果头值之间存在明显的冲突,则最严格的解释是应用(也就是最有可能保持语义透明性的解释)。

我混淆了在“缓存-控制”标题中的冲突值

3.我通过Apache web server测试了一些示例。

3.1网络拓扑学

Telnet(客户端) <->HTTP代理(Apache以代理模式工作,S1) <->(Apache,S2)

3.1.1 S1配置(用作缓存代理):

代码语言:javascript
复制
<Location />
    ProxyPass http://10.8.1.24:80/
</Location>

<IfModule mod_cache.c>

        <IfModule mod_mem_cache.c>
            CacheEnable mem /
            MCacheSize 4096
            MCacheMaxObjectCount 100
            MCacheMinObjectSize 1
            MCacheMaxObjectSize 2048
        </IfModule>

        CacheDefaultExpire 86400
</IfModule>

3.1.2 S2配置(充当真正的web服务器):

代码语言:javascript
复制
<filesMatch "\.(html|png)">
    Header set Cache-Control "max-age=5, max-age=15"
</filesMatch>

3.2测试用例

3.2.1两个“最大年龄”值

代码语言:javascript
复制
GET /index.html HTTP/1.1
Host: haha
User-Agent: telnet


HTTP/1.1 200 OK
Date: Wed, 13 Mar 2013 03:40:25 GMT
Server: Apache/2.2.23 (Win32)
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "63e62-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Cache-Control: max-age=5, max-age=35, must-revalidate
Age: 3
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>

值"max-age=5“。在这里,我认为"max-age=35“是适用的,因为这个值可以在缓存和服务器中存储内容的时间更长,以便从”语义透明性“的概念提高性能。

3.2.2最大年龄=35岁,必须重新验证

代码语言:javascript
复制
GET /index.html HTTP/1.1
Host: haha
User-Agent: telnet

HTTP/1.1 200 OK
Date: Wed, 13 Mar 2013 03:41:24 GMT
Server: Apache/2.2.23 (Win32)
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "63e62-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Cache-Control: max-age=35, must-revalidate
Age: 10
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>

应用最大值-年龄=35.在这里,我认为应该应用价值“必须重新验证”。

3.2.3最大年龄=35岁和无店铺

代码语言:javascript
复制
GET /index.html HTTP/1.1
Host: haha
User-Agent: telnet

HTTP/1.1 200 OK
Date: Wed, 13 Mar 2013 03:45:04 GMT
Server: Apache/2.2.24 (Unix)
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "63e62-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Cache-Control: max-age=35, no-store
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>

值“无存储”被应用。

3.2.4最大年龄=36和无缓存

代码语言:javascript
复制
GET /index.html HTTP/1.1
Host: haha
User-Agent: telnet

HTTP/1.1 200 OK
Date: Wed, 13 Mar 2013 06:22:14 GMT
Server: Apache/2.2.24 (Unix)
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "63e62-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Cache-Control: max-age=35, no-cache
Content-Type: text/html

<html><body><h1>It works!</h1></body></html>

值“无缓存”被应用。

参考资料: RFC2616 https://www.rfc-editor.org/rfc/rfc2616

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-13 07:03:19

我将对你所举的例子解释如下:

  • max-age=5, max-age=15max-age=5赢了,因为它的缓存时间更短,限制更大
  • max-age=5, max-age=35, must-revalidatemust-revalidate获胜,因为它要求客户端始终重新验证请求。第14.9.4节说: 为了支持某些协议特性的可靠操作,必须重新验证指令。在任何情况下,HTTP/1.1缓存都必须服从必须重新验证指令;
  • max-age=35, no-storeno-store赢了,因为它基本上意味着不应该执行缓存,这当然是最严格的限制。
  • max-age=35, no-cacheno-cache获胜,因为它类似于no-store,没有指定任何字段名,这意味着缓存不能对后续请求重用响应,这是两者中限制更多的。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15378546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档