リソース · 63
HTTPキャッシング:パーソナライズされた応答の保護
共有キャッシュ、プライベートキャッシュ、アプリケーションキャッシュを分離し、アクセス権限変更後にキー、再検証、無効化を検査します。
更新済み · 13 min
このガイドが達成するのに役立つこと
- レイヤーのインベントリ
- 保持期間の選択
- キーの検査
- 再検証と変更の実行
クイックチェック
- キャッシュなしとは、何も保持されないという意味でしょうか?
- Varyはアクセス権限を保護するのか?
- すべてのAPIをキャッシュすべきか?
手順
- 1
レイヤーのインベントリ
ブラウザ、CDN、プロキシ、サービスワーカー、およびアプリケーションのキャッシュを一覧表示する。 パブリックレスポンスとパーソナライズされたレスポンスを分類する。 HTTPポリシーは、コードで実装されたキャッシュを自動的に記述するものではない。
成果物:レイヤーと所有者の図。
- 2
保持期間の選択
RFC 9111はディレクティブを区別している。no-cacheは再利用前に検証が必要であり、no-storeは関連するHTTPストレージを禁止し、unqualified privateは共有ストレージを除外する。 いずれか一つだけではシステムの機密性を保証することはできません。
成果物:レスポンスごとの保持ポリシー。
- 3
キーの検査
メソッド、URI、および表現を変更するディメンションをチェックします。 変更はリクエストフィールドに関するものであり、認証ではありません。 アプリケーション層で省略された言語、フォーマットのネゴシエーション、およびアカウントコンテキストを探索します。
成果物:キーと分離テスト。
- 4
再検証と変更の実行
新規レスポンスと古いレスポンス、データ更新、および取り消された権限をテストします。 ETag、条件付き検証、およびオリジンが利用できない場合の動作を検査します。 以前は正しかったレスポンスも、取り消し後に機密情報となる可能性があります。
成果物:前後トレース
- 5
2つのアカウントを使用したリプレイテスト
架空のIDとマーカーを使用。 ウォームキャッシュとコールドキャッシュを使用して、同じURIへのリクエストを交互に実行。 ログアウト、直接リンク、および実際のトークンを記録しないログ記録を検証。
成果物:ネガティブテストと無効化戦略
キャッシュの速度と鮮度を測る
架空の例です。顧客や実際の観測結果を示すデータではありません。
状況
二つの読み出しは高速ですが、一方は元データの変更後も古い在庫状況を表示しています。
確認
値、版、読み出し場所、変更後の経過時間を比較し、システムの契約に沿って無効化、期限切れ、元データへのアクセスを試験します。
実行
用途ごとに許容できる古さを定め、差異を監視します。遅延が短いだけでは、配信データの整合性は証明できません。
再利用可能なワークシート
承認された観察結果を記入してください。 これらのフィールドは作業用テンプレートであり、観察結果ではありません。
| フィールド | 記録する情報 |
|---|---|
| レスポンス | 公開またはパーソナライズ。 ディメンション |
| レイヤー | キャッシュ、所有者、キー |
| ポリシー | 保持、鮮度、検証 |
| 試行 | 架空のアカウント、変更、監視 |
架空の事例
具体的な状況
架空の例:CDNが2つのテストアカウントに対して同じURIでプロファイルレスポンスを再利用します。
決定と期待される証拠
このシナリオでは、情報漏洩を検出し、ポリシーとキーを検証し、修正とアクセス取り消し後にリプレイを実行します。
メカニズムの区別
| メカニズム | 目的 | 検証または制限 |
|---|---|---|
| キャッシュなし | 検証が必要なストレージを許可する | ストレージなしとは解釈しない |
| 修飾されていないプライベート | 共有キャッシュを除外する | 機密性保証とは解釈しない |
| ストアなし | 関連する HTTP ストレージを防止する | アプリケーション キャッシュと履歴を個別にチェックする |
管理指標
| 指標 | 測定対象 | 最初のアクション |
|---|---|---|
| アカウントの分離 | 他のアカウントからのマーカーを禁止する | 本文、リンク、メタデータを検査する |
| 有効期限と検証 | ポリシーに準拠した再利用 | 有効期限と利用できないオリジンをテストする |
| 無効化の遅延 | 修正された表現までの時間 | まだ古い各レイヤーに名前を付ける |
よくある間違い
- ストレージなしとは解釈しない
- 機密性保証とは解釈しない
- アプリケーション キャッシュと履歴を個別にチェックする
よくある質問
キャッシュなしとは、何も保持されないという意味でしょうか?
いいえ。再利用前に検証が必要です。 ストアなしのようにストレージを禁止するわけではありません。
Varyはアクセス権限を保護するのか?
いいえ。表現の選択に参加します。 認証は分離されたままです。
すべてのAPIをキャッシュすべきか?
いいえ。メリットはコスト、鮮度、リスクによって異なります。 機密性の高いレスポンスの場合は、共有キャッシュを避けることが正当化される場合があります。
ETag・HTTPキャッシュ・同時更新
この言語版の詳しい参照メモは英語で提供しています。
ETag: revalidate responses and prevent lost updates
An ETag is an opaque validator for the selected representation. It compares versions; it is neither authorisation nor an access token, and it need not be a file hash. Personalised responses require separate decisions about access, cache selection and HTTP conditions.
Local teaching model: a representation already exists; at most one conditional field contains a single ETag or *. GET, HEAD and PUT are covered. Tag lists, date validators, ranges, creation, combined conditions and the already-succeeded modification exception are excluded. No network call, storage or state change occurs; this does not test your API.
Strong and weak ETag comparison serve different purposes
If-Match requires strong comparison: neither tag may start with W/. If-None-Match uses weak comparison, matching the opaque values regardless of W/. Values remain case-sensitive. The * wildcard checks representation existence here, not a particular version.
| Current tag | Received tag | Strong comparison | Weak comparison |
|---|---|---|---|
| "v1" | "v1" | Matches | Matches |
| "v1" | W/"v1" | Does not match | Matches |
| W/"v1" | W/"v1" | Does not match | Matches |
| "v1" | "v2" | Does not match | Does not match |
| "v1" | "V1" | Does not match | Does not match |
Simulate an HTTP decision without contacting a server
The six parameters yield 432 combinations. Requiring a conditional field and selecting 204 for successful PUT are policies of this fictional scenario. Requiring any condition does not prevent every lost update: If-Match: * compares no version.
Model decision :
304: If-None-Match finds a weak match for GET or HEAD. Reuse the stored representation under cache rules with the revalidation metadata.
304 and 204: no response content.
Request excerpt
GET /demo/resource HTTP/1.1
Host: api.example.test
If-None-Match: W/"v1"Response excerpt
HTTP/1.1 304 Not Modified
Date: Thu, 22 Oct 2026 00:00:00 GMT
ETag: "v1"
Cache-Control: private, no-cacheFictional HTTP/1.1 excerpts for reading: bodies are omitted even where allowed. api.example.test is an example domain. The date is fixed. This model does not update the ETag after PUT; the separate walkthrough follows successive versions.
Ten reproducible situations
| Fictional situation | Condition and expected outcome | Interpretation |
|---|---|---|
| Read using a weak tag | GET · "v1"Access allowed · Conditional field optional | W/"v1" and "v1" match weakly. |
| Different client version | GET · "v1"Access allowed · Conditional field optional | The client needs the selected representation. |
| HEAD revalidation | HEAD · "v1"Access allowed · Conditional field optional | The status can be 304; the response has no content. |
| Write based on an old version | PUT · "v2"Access allowed · Conditional field optional | Read again and resolve the conflict before retrying. |
| Weak tag with If-Match | PUT · "v1"Access allowed · Conditional field optional | Strong comparison rejects a weak tag. |
| Required condition absent on PUT | PUT · "v1"Access allowed · Conditional field required | 428 follows the policy announced by this API. |
| Access denied despite matching tag | GET · "v1"Access denied · Conditional field optional | Authorisation precedes HTTP conditions. |
| Write on the correct version | PUT · "v1"Access allowed · Conditional field required | The model accepts PUT and selects a 204 success. |
| If-None-Match: * on existing data | PUT · "v1"Access allowed · Conditional field optional | The wildcard matches any existing representation. |
| If-Match: * on existing data | PUT · W/"v1"Access allowed · Conditional field required | The wildcard passes even with a weak current tag: it does not protect a version. |
Four rules for a personalised response
| Response field | HTTP effect within this scope | Evidence to retain |
|---|---|---|
| Cache-Control: no-cache | Unqualified no-cache permits storage, but any reuse needs successful validation with the origin server. | Observe a conditional round trip; do not read no-cache as a storage prohibition. |
| Cache-Control: no-store | Forbids storage by private and shared HTTP caches. It is not a general privacy guarantee. | Also review logs, history, screenshots and application storage. |
| Cache-Control: private | Unqualified private forbids storage by a shared cache; a private cache may store under the other constraints. | Distinguish browser, proxy and CDN. A directive does not replace access checks. |
| Vary | Adds the named request fields to selection of a stored response. It does not decide who may access a resource. | Test relevant variants. Do not assume a cookie or Authorization automatically prevents all caching. |
Useful API acceptance evidence
- Expected request and status: method, test resource, access rights, conditional field and current ETag. Use fictional data and remove secrets.
- Observed response: status, ETag, Date, Cache-Control, Vary and no content for HEAD, 204 or 304. A 304 must carry the required metadata that would have accompanied the 200.
- Concurrency: verify that a stale write fails without changing the resource; retain the conflict-resolution decision. Do not blindly replace the ETag and resend the same write.
Follow the two-client conflict →
Primary references and limits
The standards define HTTP conditions and caching. The ten cases, laboratory and two-client walkthrough are original illustrations. Displayed results are calculated by this local model, not measurements of this site or your infrastructure.
- IETF · RFC 9110 — HTTP Semantics · June 2022 · STD 97
§8.8.3.2; §13.1.1–13.1.2; §13.2; §15.3.5; §15.4.5 - IETF · RFC 9111 — HTTP Caching · June 2022 · STD 98
§4.1; §4.3; §5.2.2.4–5.2.2.5; §5.2.2.7 - IETF · RFC 6585 — Additional HTTP Status Codes · April 2012 · Standards Track
§3 · 428 Precondition Required
References reviewed
公式参照文献
参照文献はメソッドを裏付けるものです。 チェックは状況に合わせて調整してください。 これらは認証ではありません。 元の参照文献のタイトルやソース文書は別の言語で書かれている場合があります。
参照資料の確認日 .
