Ressourcen · 63
HTTP-Caching: Personalisierte Antworten schützen
Geteilte, private und Anwendungs-Caches trennen, Schlüssel überprüfen, erneut validieren und ungültig machen, nachdem Zugriffsrechte geändert wurden.
Aktualisiert · 6 min
Wozu dieser Leitfaden beiträgt
- Inventarebenen
- Wählen Sie Aufbewahrung
- Schlüssel prüfen
- Übungsverlängerung und -änderung
Kurzcheck
- Bedeutet No-Cache, dass nichts gespeichert wird?
- Schützt Vary Zugriffsrechte?
- Sollte jede API zwischengespeichert werden?
Schritt-für-Schritt-Anleitung
- 1
Inventarebenen
Browser-, CDN-, Proxy-, Service-Worker- und Anwendungs-Caches auflisten. Klassifizieren Sie öffentliche und personalisierte Antworten. Eine HTTP-Richtlinie beschreibt nicht automatisch das im Code implementierte Caching.
Liefergegenstand: Ebenen- und Eigentümerdiagramm.
- 2
Wählen Sie Aufbewahrung
RFC 9111 unterscheidet Richtlinien: No-Cache erfordert eine Validierung vor der Wiederverwendung, No-Store verbietet den entsprechenden HTTP-Speicher und unqualifiziertes Private schließt Shared Storage aus. Keiner allein garantiert die Vertraulichkeit des Systems.
Lieferinhalt: Aufbewahrungsrichtlinie pro Antwort.
- 3
Schlüssel prüfen
Methode, URI und Dimensionen beim Ändern einer Darstellung prüfen. Variieren Sie die Anforderungsfelder für Anliegen. es handelt sich nicht um eine Genehmigung. Suchen Sie nach ausgelassener Sprache, Formataushandlung und Kontokontext in Anwendungsebenen.
Lieferinhalt: Schlüssel und Trennungstests.
- 4
Übungsverlängerung und -änderung
Testen Sie neue und veraltete Antworten, Datenaktualisierungen und widerrufene Rechte. Untersuchen Sie ETag, bedingte Validierung und Ursprungsunverfügbarkeitsverhalten. Eine vormals korrekte Antwort kann nach einem Widerruf empfindlich werden.
Lieferbar: Vorher-Nachher-Spuren.
- 5
Wiederholung mit zwei Konten
Verwenden Sie fiktive Identitäten und Markierungen. Alternative Anfragen an denselben URI mit warmen und kalten Caches. Überprüfen Sie Abmeldung, direkte Links und Protokollierung, ohne echte Token aufzuzeichnen.
Liefergegenstand: Negativtests und Invalidierungsstrategie.
Neben Cachegeschwindigkeit auch Aktualität messen
Fiktives Beispiel: Diese Daten beschreiben keine Kunden oder beobachteten Ergebnisse.
Situation.
Zwei Lesezugriffe sind schnell, doch einer zeigt nach einer Änderung der Quelle noch die alte Verfügbarkeit.
Prüfen.
Wert, Version, Leseort und Zeit seit der Änderung vergleichen. Invalidierung, Ablauf und Zugriff auf die Quelle gemäß Systemvertrag testen.
Handeln.
Zulässige Veralterung je Anwendung definieren und Abweichungen überwachen. Niedrigere Latenz belegt keine konsistenten Auslieferungsdaten.
Wiederverwendbares Arbeitsblatt
Ergänzen Sie Ihre autorisierten Beobachtungen. Bei diesen Feldern handelt es sich um eine Arbeitsvorlage, nicht um beobachtete Ergebnisse.
| Feld | Zu erfassende Informationen |
|---|---|
| Antwort | Öffentlich oder personalisiert; Abmessungen |
| Ebene | Cache, Besitzer und Schlüssel |
| Richtlinie | Aufbewahrung, Frische und Validierung |
| Testversion | Fiktive Darstellung, Veränderung und Beobachtung |
Fiktives Arbeitsbeispiel
Beispielhafte Situation
Fiktives Beispiel: Ein CDN verwendet eine Profilantwort unter derselben URI für zwei Testkonten wieder.
Entscheidung und erwartete Beweise
Das Szenario erkennt Lecks, untersucht Richtlinien und Schlüssel und wird dann nach Korrektur und Zugriffssperre erneut abgespielt.
Unterscheiden Sie die Mechanismen
| Mechanismus | Zweck | Überprüfung oder Einschränkung |
|---|---|---|
| kein Cache | Speicherung mit erforderlicher Validierung zulassen | Lesen Sie es nicht, da kein Speicher vorhanden ist |
| Unqualifizierter Privatmann | Gemeinsames Caching ausschließen | Lesen Sie es nicht als Vertraulichkeitsgarantie |
| kein Laden | Verhindern Sie die entsprechende HTTP-Speicherung | Anwendungscaches und Verlauf separat prüfen |
Managementindikatoren
| Indikator | Was es misst | Erste Aktion |
|---|---|---|
| Kontotrennung | Keine Markierung von einem anderen Konto | Überprüfen Sie Text, Links und Metadaten |
| Alter und Validierung | Wiederverwendung im Einklang mit der Richtlinie | Testablauf und nicht verfügbarer Ursprung |
| Ungültigkeitsverzögerung | Zeit bis zur korrigierten Darstellung | Benennen Sie jede noch veraltete Ebene |
Häufige Fallstricke
- Lesen Sie es nicht, da kein Speicher vorhanden ist
- Lesen Sie es nicht als Vertraulichkeitsgarantie
- Anwendungscaches und Verlauf separat prüfen
Häufig gestellte Fragen
Bedeutet No-Cache, dass nichts gespeichert wird?
Nein. Vor der Wiederverwendung ist eine Validierung erforderlich. Es verbietet die Speicherung nicht wie No-Store.
Schützt Vary Zugriffsrechte?
Nein. Es beteiligt sich an der Vertretungsauswahl; Die Autorisierung bleibt getrennt.
Sollte jede API zwischengespeichert werden?
Nein. Der Nutzen hängt von Kosten, Frische und Risiko ab. Sensible Antworten können es rechtfertigen, gemeinsame Caches zu meiden.
ETag, HTTP-Cache und gleichzeitige Änderungen
Ausführliche Hinweise stehen in dieser Ausgabe auf Englisch zur Verfügung.
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
Offizielle Referenzen
Die Referenzen unterstützen die Methode. Passen Sie die Prüfungen an Ihren Kontext an; sie stellen keine Zertifizierung dar. Originalreferenztitel und Quelldokumente können in einer anderen Sprache verfasst sein.
Referenzen geprüft am .
