Slide 1

Slide 1 text

Caching in HTTP SJ 2016/07/25 Email: [email protected] Blog: http://blog.toright.com

Slide 2

Slide 2 text

回顧 HTTP 1.1 的設計理念 Architectural Styles and the Design of Network-based Software Architectures (by Roy Thomas Fielding) CHAPTER 5. Representational State Transfer (REST)

Slide 3

Slide 3 text

HTTP Features ● HTTP 1.1 設計 Cache 的目的在降低 Request 與 Full Response ● 以下兩個主要的設計理念 ○ Expiration ○ Validation ● 實作上透過 Header 讓 Server 與 Client 可以 自由定義 Cache 的方式

Slide 4

Slide 4 text

HTTP 1.0 與 HTTP 1.1 Caching Difference HTTP 1.0 Reponse Cache Header ○ Expires ○ Pragma HTTP 1.1 Reponse Cache Header ○ Cache-Control

Slide 5

Slide 5 text

介紹 HTTP 1.1 Cache-Control Header ● Response Cache Header ○ no-store 完全不 Cache ○ no-cache 允許 Cache 但是每次都會檢查 Cache 狀態 ○ max-age 設定要 Cache 幾秒 ○ private Cache 只給目前使用者使用 ○ public Cache 可共用 (HTTPS不可共用) ○ must-revalidate 交由 Client 自行決定要不要使用 Cache ● 可以混搭

Slide 6

Slide 6 text

如何檢查 Cache 是否有效? ● 時間導向 (秒為單位) Last-Modified / If-Modified-Since ● 檔案內容導向 (Hash) ETag / If-None-Match

Slide 7

Slide 7 text

Cache-Control: no-store

Slide 8

Slide 8 text

Cache-Control: no-cache

Slide 9

Slide 9 text

Cache-Control: max-age

Slide 10

Slide 10 text

Cache-Control: private

Slide 11

Slide 11 text

Cache-Control: public

Slide 12

Slide 12 text

Cache-Control: must-revalidate

Slide 13

Slide 13 text

Reference ● HTTP 1.1 RFC 2616 - 14.9 Cache-Control ● HTTP 1.1 RFC 2616 - 13 Caching in HTTP ● Architectural Styles and the Design of Network-based Software Architectures - 5 Representational State Transfer (REST)

Slide 14

Slide 14 text

Thanks! The End Email: [email protected] Blog: http://blog.toright.com