3

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

语义透明

  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 Mechanisms”这句话

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

我混淆了“Cache-Control”标头中的那些冲突值

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

3.1 网络拓扑

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

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

<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服务器工作):

<filesMatch "\.(html|png)">
    Header set Cache-Control "max-age=5, max-age=15"
</filesMatch>

3.2 测试用例

3.2.1 两个“max-age”值

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 max-age=35 并且必须重新验证

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>

应用值 max-age=35。在这里,我认为应该应用价值“必须重新验证”。

3.2.3 max-age=35 且无存储

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 max-age=36 和无缓存

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

4

1 回答 1

0

我将您提供的示例解释如下:

  • max-age=5, max-age=15:max-age=5获胜,因为它的缓存时间更短,限制性更强

  • max-age=5, max-age=35, must-revalidatemust-revalidate获胜,因为它要求客户端始终重新验证请求。第 14.9.4 节说:

      The must-revalidate directive is necessary to support reliable
      operation for certain protocol features. In all circumstances an
      HTTP/1.1 cache MUST obey the must-revalidate directive;
    
  • max-age=35, no-store:no-store获胜,因为它基本上意味着不应该执行缓存,这当然是最严格的。

  • max-age=35, no-cache:no-cache获胜,因为它类似于no-store并且不指定任何字段名称,这意味着缓存不能将响应重用于后续请求,这是两者中限制性更强的。

于 2013-03-13T07:03:19.877 回答