Bronnen · 63
HTTP-caching: bescherm gepersonaliseerde antwoorden
Scheid gedeelde, privé- en applicatiecaches, inspecteer sleutels, hervalidatie en ongeldigverklaring na wijzigingen in toegangsrechten.
Bijgewerkt · 6 min
Wat deze handleiding helpt bereiken
- Inventarisatielagen
- Retentie kiezen
- Sleutels inspecteren
- Hervalidatie en wijziging uitvoeren
Snelle controle
- Betekent geen cache dat er niets wordt bewaard?
- Beschermt Vary toegangsrechten?
- Moet elke API in de cache worden opgeslagen?
Stapsgewijze methode
- 1
Inventarisatielagen
Lijst browser-, CDN-, proxy-, service worker- en applicatiecaches. Classificeer openbare en gepersonaliseerde reacties. Een HTTP-beleid beschrijft niet automatisch de caching die in de code is geïmplementeerd.
Resultaat: diagram van lagen en eigenaren.
- 2
Retentie kiezen
RFC 9111 onderscheidt richtlijnen: 'no-cache' vereist validatie vóór hergebruik, 'no-store' verbiedt de relevante HTTP-opslag en 'unqualified private' sluit gedeelde opslag uit. Geen enkele op zich garandeert systeemvertrouwelijkheid.
Resultaat: bewaarbeleid per reactie.
- 3
Sleutels inspecteren
Controleer de methode, URI en dimensies die een weergave wijzigen. Variatie betreft aanvraagvelden; het betreft geen autorisatie. Zoek naar weggelaten taal, formaatonderhandeling en accountcontext in applicatielagen.
Resultaat: sleutels en scheidingstests.
- 4
Hervalidatie en wijziging uitvoeren
Test nieuwe en verouderde reacties, gegevensupdates en ingetrokken rechten. Inspecteer ETag, voorwaardelijke validatie en gedrag bij onbeschikbare oorsprong. Een voorheen correcte reactie kan gevoelig worden na intrekking.
Resultaat: traceringen voor en na.
- 5
Herhaling met twee accounts
Gebruik fictieve identiteiten en markers. Wissel verzoeken af naar dezelfde URI met warme en koude caches. Controleer uitloggen, directe links en logging zonder echte tokens vast te leggen.
Resultaat: negatieve tests en invalidatiestrategie.
Meet ook hoe actueel cachegegevens zijn
Fictief voorbeeld: deze gegevens beschrijven geen klant of waargenomen resultaat.
Situatie
Twee leesacties zijn snel, maar één toont na een bronwijziging nog de oude beschikbaarheid.
Controleren
Vergelijk waarde, versie, leeslocatie en tijd sinds wijziging. Test ongeldig maken, verlopen en toegang tot de bron volgens de systeemafspraken.
Handelen
Bepaal aanvaardbare veroudering per toepassing en bewaak verschillen. Lagere vertraging bewijst geen consistentie van geleverde gegevens.
Herbruikbaar werkblad
Vul in met uw geautoriseerde observaties. Deze velden zijn een werksjabloon, geen waargenomen resultaten.
| Veld | Informatie om vast te leggen |
|---|---|
| Reactie | Openbaar of gepersonaliseerd; dimensies |
| Laag | Cache, eigenaar en sleutel |
| Beleid | Bewaring, actualiteit en validatie |
| Proef | Fictief account, wijziging en observatie |
Fictief uitgewerkt voorbeeld
Illustratieve situatie
Fictief voorbeeld: een CDN hergebruikt een profielreactie op dezelfde URI voor twee testaccounts.
Beslissing en verwachte bewijs
Het scenario detecteert lekken, onderzoekt beleid en sleutels en speelt vervolgens opnieuw af na correctie en intrekking van toegang.
Onderscheid de mechanismen
| Mechanisme | Doel | Verificatie of beperking |
|---|---|---|
| geen cache | Opslag toestaan met vereiste validatie | Niet interpreteren als geen opslag |
| Niet-gekwalificeerd privé | Gedeelde caching uitsluiten | Niet interpreteren als een vertrouwelijkheidsgarantie |
| geen opslag | Voorkom de relevante HTTP-opslag | Controleer applicatiecaches en geschiedenis afzonderlijk |
Managementindicatoren
| Indicator | Wat het meet | Eerste actie |
|---|---|---|
| Accountscheiding | Geen markering van een ander account | Inspecteer body, links en metadata |
| Leeftijd en validatie | Hergebruik in overeenstemming met beleid | Test vervaldatum en niet-beschikbare oorsprong |
| Ongeldigmakingsvertraging | Tijd tot gecorrigeerde weergave | Benoem elke laag die nog steeds verouderd is |
Veelvoorkomende fouten
- Niet interpreteren als geen opslag
- Niet interpreteren als een vertrouwelijkheidsgarantie
- Controleer applicatiecaches en geschiedenis afzonderlijk
Veelgestelde vragen
Betekent geen cache dat er niets wordt bewaard?
Nee. Het vereist validatie vóór hergebruik; het verbiedt opslag niet zoals 'geen opslag' dat wel doet.
Beschermt Vary toegangsrechten?
Nee. Het neemt deel aan de selectie van de weergave; Autorisatie blijft gescheiden.
Moet elke API in de cache worden opgeslagen?
Nee. Voordelen hangen af van kosten, actualiteit en risico. Gevoelige reacties kunnen het vermijden van gedeelde caches rechtvaardigen.
ETag, HTTP-cache en gelijktijdige wijzigingen
De uitgebreide toelichtingen zijn in deze editie beschikbaar in het Engels.
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
Officiële referenties
Referenties ondersteunen de methode. Pas controles aan uw context aan; ze zijn geen certificering. Originele referentietitels en brondocumenten kunnen in een andere taal zijn.
Bronnen geraadpleegd op .
