HTTP Cache 再確認

HTTP Cache 再確認

HTML5 10th Anniversary での登壇セッション「HTTP Cache 再確認」の投影スライドです。

Murachi Akira PRO

October 27, 2024

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

42 slides
  1. About me • Murachi Akira aka hebikuzure ( 村地 彰

    ) • 株式会社エクシードワン 技術フェロー • 株式会社シーピーエス 技術教育スペシャリスト • 専門学校東京テクニカルカレッジ非常勤講師 • Microsoft MVP (Most Valuable Professional) • Since Apr. 2011 ( 14 Years! ) • Award Category: Windows and Devices -Windows Cloud and Datacenter Management –Windows Server • Expertise • Windows client / user management and security • Microsoft 365, Active Directory, Microsoft Endpoint Manager https://www.linkedin.com/in/akiramurachi/ https://www.facebook.com/amurachi/ https://twitter.com/hebikuzure 2
  2. インターネット標準の位置づけ • 最新の仕様は RFC 9111- HTTP Caching(June 2022) • https://datatracker.ietf.org/doc/rfc9111/

    • それまでの仕様は RFC 7234 - Hypertext Transfer Protocol (HTTP/1.1): Caching(June 2014) • https://datatracker.ietf.org/doc/html/rfc7234 • RFC 7234 では HTTP/2・HTTP/3 の新仕様が考慮され ていなかった • RFC 7234 には曖昧さが残っていた 13
  3. 読み取り • HTTP ヘッダーを読み取って理解できる 17 Origin Server User Agent HTTP/1.1

    200 OK Content-Type: text/plain Transfer-Encoding: chunked Connection: close
  4. 「読み取りできない」の例外 • HTTPS インターセプトを行えば、 HTTPS レスポンスをキャッシュできる 19 Origin Server User

    Agent óÿa pHYs Ä Ä• + lIDATx- ’ ?HÃPÆoJJQ°S¡Ð¥tRœ ê`ëTб› tpŠ HTTP/1.1 200 OK Content-Type: text/plain Transfer-Encoding: chunked Connection: close HTTPS インターセプト
  5. キャッシュの種類 • プライベート キャッシュ • 単一のユーザー専用のキャッシュ • 通常はブラウザーなどの User Agent

    の内部キャッシュ • 共有キャッシュ • 複数のユーザーへの応答に利用できるキャッシュ • 通常はプロキシや CDN などの中間キャッシュ 27
  6. キャッシュ利用前の確認 • キャッシュ利用の前に、Origin Server により新しいコンテ ンツがないか確認させるには Cache-Control: no-cache HTTP ヘッダーを指定する

    33 Cache-Control: no-cache 再リクエスト キャッシュを レスポンス する前に サーバーに確認 HTTP 304 Not Modified が返れば キャッシュからレスポンス
  7. 有効期限の設定 • キャッシュの有効期限は Cache-Control: max-age=xxxx (xxxx は秒数) HTTP ヘッダーで指定する •

    xxxx は Origin Server でレスポンスが生成されてからの 秒数 • 中間キャッシュで保持されていた時間も 有効期限に含まれる • 中間キャッシュで保持されていた時間は Age HTTP ヘッダーで User Agent に示される 37
  8. 中間キャッシュと有効期限 38 Cache-Control: max-age=100 User Agent(1) User Agent(2) Cache Cache-Control:

    max-age=100 Age: 50 Cache User Agent(2) のキャッシュの有効期限は 100 – 50 = 50 秒
  9. 推奨事項 • 効率的にキャッシュを利用できるよう、適切な Cache-Control ヘッダーを使用する • プライベートなコンテンツには必ず Cache-Control: private を指定する

    • キャッシュの無効化は Cache-Control: no-store ※ 間違えて no-cache を使わないよう注意 • キャッシュ可能なコンテンツには必ず max-age を指定 39
  10. 参考情報 • RFC 9111 - HTTP Caching • https://datatracker.ietf.org/doc/rfc9111/ •

    HTTP キャッシュ - HTTP | MDN • https://developer.mozilla.org/ja/docs/Web/HTTP/Caching • Cache-Control - HTTP | MDN • https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/ Cache-Control 41

More Decks by Murachi Akira

Other Decks in Technology