簡體   English   中英

如何在“Cache-Control machanism”部分理解RFC2616的“語義透明”?

[英]How to understand “semantically transparent” of RFC2616 in “Cache-Control machanism” section?

1.從RFC2616的sec“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標頭允許客戶端或服務器在請求或響應中傳輸各種指令。 這些指令通常會覆蓋默認的緩存算法。 作為一般規則,如果標頭值之間存在任何明顯的沖突,則應用最嚴格的解釋 (即,最有可能保留語義透明性的解釋)。

我在“Cache-Control”標題中混淆了那些沖突值

3.我通過Apache Web服務器測試一些例子

3.1 Web拓撲學

Telnet(客戶端)< - > HTTP代理(apache在代理模式下工作,S1)< - > Web服務器(Apache,S2)

3.1.1 S1 configurarion(作為緩存代理):

<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兩個“最大年齡”值

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>

應用值“no-store”。

3.2.4 max-age = 36和no-cache

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>

應用值“no-cache”。

參考文獻:RFC2616 http://tools.ietf.org/html/rfc2616

我會解釋你給出的例子如下:

  • max-age=5, max-age=15max-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-storeno-store wins,因為它基本上意味着不應該執行緩存,這肯定是最嚴格的。

  • max-age=35, no-cacheno-cache勝利,因為它類似於no-store而且沒有指定任何字段名稱,這意味着緩存不能重用后續請求的響應,這是更嚴格的兩個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM