初探 HTTP 1.1 Cache 機制,透過簡單的實驗來說明瀏覽器對於 HTPP Cache 的實作策略。
Caching in HTTPSJ2016/07/25Email: [email protected]Blog: http://blog.toright.com
View Slide
回顧 HTTP 1.1 的設計理念Architectural Styles and the Design of Network-based Software Architectures (by Roy ThomasFielding)CHAPTER 5. Representational State Transfer (REST)
HTTP Features● HTTP 1.1 設計 Cache 的目的在降低Request 與 Full Response● 以下兩個主要的設計理念○ Expiration○ Validation● 實作上透過 Header 讓 Server 與 Client 可以自由定義 Cache 的方式
HTTP 1.0 與 HTTP 1.1 Caching DifferenceHTTP 1.0 Reponse Cache Header○ Expires○ PragmaHTTP 1.1 Reponse Cache Header○ Cache-Control
介紹 HTTP 1.1 Cache-Control Header● Response Cache Header○ no-store完全不 Cache○ no-cache允許 Cache 但是每次都會檢查 Cache 狀態○ max-age設定要 Cache 幾秒○ privateCache 只給目前使用者使用○ publicCache 可共用 (HTTPS不可共用)○ must-revalidate交由 Client 自行決定要不要使用 Cache● 可以混搭
如何檢查 Cache 是否有效?● 時間導向 (秒為單位)Last-Modified / If-Modified-Since● 檔案內容導向 (Hash)ETag / If-None-Match
Cache-Control: no-store
Cache-Control: no-cache
Cache-Control: max-age
Cache-Control: private
Cache-Control: public
Cache-Control: must-revalidate
Reference● HTTP 1.1 RFC 2616 - 14.9 Cache-Control● HTTP 1.1 RFC 2616 - 13 Caching in HTTP● Architectural Styles and the Design ofNetwork-based Software Architectures - 5Representational State Transfer (REST)
Thanks!The EndEmail: [email protected]Blog: http://blog.toright.com