リソース · 63

HTTPキャッシング:パーソナライズされた応答の保護

共有キャッシュ、プライベートキャッシュ、アプリケーションキャッシュを分離し、アクセス権限変更後にキー、再検証、無効化を検査します。

更新済み · 13 min

サーバーとネットワーク設備の無人セキュア通路 AIで生成した編集用イラスト

このガイドが達成するのに役立つこと

  • レイヤーのインベントリ
  • 保持期間の選択
  • キーの検査
  • 再検証と変更の実行

クイックチェック

  • キャッシュなしとは、何も保持されないという意味でしょうか?
  • Varyはアクセス権限を保護するのか?
  • すべてのAPIをキャッシュすべきか?

手順

  1. 1

    レイヤーのインベントリ

    ブラウザ、CDN、プロキシ、サービスワーカー、およびアプリケーションのキャッシュを一覧表示する。 パブリックレスポンスとパーソナライズされたレスポンスを分類する。 HTTPポリシーは、コードで実装されたキャッシュを自動的に記述するものではない。

    成果物:レイヤーと所有者の図。

  2. 2

    保持期間の選択

    RFC 9111はディレクティブを区別している。no-cacheは再利用前に検証が必要であり、no-storeは関連するHTTPストレージを禁止し、unqualified privateは共有ストレージを除外する。 いずれか一つだけではシステムの機密性を保証することはできません。

    成果物:レスポンスごとの保持ポリシー。

  3. 3

    キーの検査

    メソッド、URI、および表現を変更するディメンションをチェックします。 変更はリクエストフィールドに関するものであり、認証ではありません。 アプリケーション層で省略された言語、フォーマットのネゴシエーション、およびアカウントコンテキストを探索します。

    成果物:キーと分離テスト。

  4. 4

    再検証と変更の実行

    新規レスポンスと古いレスポンス、データ更新、および取り消された権限をテストします。 ETag、条件付き検証、およびオリジンが利用できない場合の動作を検査します。 以前は正しかったレスポンスも、取り消し後に機密情報となる可能性があります。

    成果物:前後トレース

  5. 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.

架空の無人ネットワーク実験室。琥珀色の照明の下、暗い作業台に機器が並ぶ。 AIで生成した編集用イラスト
Generated conceptual scene: a fictional empty network laboratory. It shows neither a real facility nor a protocol measurement.

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.

Strong and weak ETag comparison serve different purposes
Current tagReceived tagStrong comparisonWeak comparison
"v1""v1"MatchesMatches
"v1"W/"v1"Does not matchMatches
W/"v1"W/"v1"Does not matchMatches
"v1""v2"Does not matchDoes not match
"v1""V1"Does not matchDoes 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

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-cache

Fictional 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

Ten reproducible situations
Fictional situationCondition and expected outcomeInterpretation
Read using a weak tagGET · "v1"
If-None-Match: W/"v1" → 304

Access allowed · Conditional field optional

W/"v1" and "v1" match weakly.
Different client versionGET · "v1"
If-None-Match: "v2" → 200

Access allowed · Conditional field optional

The client needs the selected representation.
HEAD revalidationHEAD · "v1"
If-None-Match: "v1" → 304

Access allowed · Conditional field optional

The status can be 304; the response has no content.
Write based on an old versionPUT · "v2"
If-Match: "v1" → 412

Access allowed · Conditional field optional

Read again and resolve the conflict before retrying.
Weak tag with If-MatchPUT · "v1"
If-Match: W/"v1" → 412

Access allowed · Conditional field optional

Strong comparison rejects a weak tag.
Required condition absent on PUTPUT · "v1"
none → 428

Access allowed · Conditional field required

428 follows the policy announced by this API.
Access denied despite matching tagGET · "v1"
If-None-Match: "v1" → 403

Access denied · Conditional field optional

Authorisation precedes HTTP conditions.
Write on the correct versionPUT · "v1"
If-Match: "v1" → 204

Access allowed · Conditional field required

The model accepts PUT and selects a 204 success.
If-None-Match: * on existing dataPUT · "v1"
If-None-Match: * → 412

Access allowed · Conditional field optional

The wildcard matches any existing representation.
If-Match: * on existing dataPUT · W/"v1"
If-Match: * → 204

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

Four rules for a personalised response
Response fieldHTTP effect within this scopeEvidence to retain
Cache-Control: no-cacheUnqualified 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-storeForbids storage by private and shared HTTP caches. It is not a general privacy guarantee.Also review logs, history, screenshots and application storage.
Cache-Control: privateUnqualified 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.
VaryAdds 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.

References reviewed

公式参照文献

参照文献はメソッドを裏付けるものです。 チェックは状況に合わせて調整してください。 これらは認証ではありません。 元の参照文献のタイトルやソース文書は別の言語で書かれている場合があります。

参照資料の確認日 .