Resources · 63

HTTP caching: protect personalized responses

Separate shared, private and application caches, inspect keys, revalidation and invalidation after access-right changes.

· 7 min

Empty secure server and network corridor AI-generated editorial illustration

What this guide helps achieve

  • Inventory layers
  • Choose retention
  • Inspect keys
  • Exercise revalidation and change

Quick check

  • Does no-cache mean nothing is retained?
  • Does Vary protect access rights?
  • Should every API be cached?

Step-by-step method

  1. 01

    Inventory layers

    List browser, CDN, proxy, service worker and application caches. Classify public and personalized responses. An HTTP policy does not automatically describe caching implemented in code.

    Deliverable: layers and owners diagram.

  2. 02

    Choose retention

    RFC 9111 distinguishes directives: no-cache requires validation before reuse, no-store prohibits the relevant HTTP storage, and unqualified private excludes shared storage. None alone guarantees system confidentiality.

    Deliverable: retention policy per response.

  3. 03

    Inspect keys

    Check method, URI and dimensions changing a representation. Vary concerns request fields; it is not authorisation. Seek omitted language, format negotiation and account context in application layers.

    Deliverable: keys and separation tests.

  4. 04

    Exercise revalidation and change

    Test fresh and stale responses, data updates and revoked rights. Inspect ETag, conditional validation and origin-unavailable behaviour. A formerly correct response may become sensitive after revocation.

    Deliverable: before-and-after traces.

  5. 05

    Replay with two accounts

    Use fictional identities and markers. Alternate requests to the same URI with warm and cold caches. Check logout, direct links and logging without recording real tokens.

    Deliverable: negative tests and invalidation strategy.

Four situations for testing the method

Fictional teaching cases. Each situation connects a signal, a check and a decision bounded by evidence; none represents a client outcome.

Fictional situationConcrete checkDecision and limit
Do not share analysis results across private contexts — A voice-analysis response is reused in another session because the cache key omits the authorised context.Use fictional data to cross-test two accounts, keys, permissions, retention and purge. Include errors and logs.Prevent cross-context reuse and limit retained data. A technically cacheable response is not necessarily appropriate for a shared cache.
A cache must distinguish JSON representations — Two route versions return different schemas, and a client receives a cached response for the other version.Test version selection and representation dimensions, then compare cache keys with client validation.Separate representations and handle incompatibility explicitly. Parseable JSON may still violate the expected contract.
Check the same cache policy across clients — Python, PHP and JavaScript clients handle validators and retained content differently, producing divergent results after an update.Replay the same request-response sequence including headers. Check when each client reuses, revalidates or replaces local content.Document expected common behaviour instead of assuming a library enforces the intended policy. Include intermediate caches.
Measure freshness as well as distributed-cache speed — Two reads are fast, but one still shows old availability after the source changes.Compare value, version, reading location and time since change. Test invalidation, expiry and source access against the system contract.Define acceptable freshness per use and monitor divergence. A latency improvement does not establish consistency of served data.

Reusable worksheet

Complete with your authorised observations. These fields are a working template, not observed results.

FieldInformation to record
ResponsePublic or personalized; dimensions
LayerCache, owner and key
PolicyRetention, freshness and validation
TrialFictional account, change and observation

Worked example

Illustrative situation

Fictional example: a CDN reuses a profile response at the same URI for two test accounts.

Decision and expected evidence

The scenario detects leakage, examines policy and keys, then replays after correction and access revocation.

Distinguish the mechanisms

MechanismPurposeCheck or limitation
no-cachePermit storage with required validationDo not read it as no storage
Unqualified privateExclude shared cachingDo not read it as a confidentiality guarantee
no-storePrevent the relevant HTTP storageCheck application caches and history separately

Management indicators

IndicatorWhat it measuresFirst action
Account separationNo marker from another accountInspect body, links and metadata
Age and validationReuse consistent with policyTest expiry and unavailable origin
Invalidation delayTime until corrected representationName each layer still stale

Common pitfalls

  • Do not read it as no storage
  • Do not read it as a confidentiality guarantee
  • Check application caches and history separately

Frequently asked questions

Does no-cache mean nothing is retained?

No. It requires validation before reuse; it does not prohibit storage as no-store does.

Does Vary protect access rights?

No. It participates in representation selection; authorisation remains separate.

Should every API be cached?

No. Benefits depend on cost, freshness and risk. Sensitive responses may justify avoiding shared caches.

ETag, HTTP caching and concurrent updates

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.

Fictional empty network laboratory with gateway appliances on a dark amber-lit workbench. AI-generated editorial illustration
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

Official references

References consulted: . The method and worksheet propose checks to adapt to your context; they do not constitute certification.