COMPUTER ENGINEER

Jump to examples
Blog
HTTP / HTTPS / TLS6 min study
54/ 70

Caching and conditional requests

Vary, CDNs and cache keys

Wrong cache keys can serve the wrong representation.

UnderstandStudy an examplePractise

Understand the concept

Cache keys can include method, query handling and selected fields, not merely URLs. Vary separates request-header-dependent representations. If a site selects language through a cookie, varying only by Accept-Language does not encode that choice.

Design authentication and cookie isolation before shared caching. Keying on every cookie can create excessive cardinality; sometimes not caching is correct. Authenticated shared-cache reuse has special rules and should not be overridden casually.

Query normalisation must preserve semantics. Purges, TTLs and deployment invalidation differ. A HIT does not prove correct content: test users, languages and origins. Keep intermediary and application assumptions aligned to prevent cache-key mismatches.

WHEN TO USE IT

Maintain correctness in bilingual CDN delivery.

COMMON PITFALL

Equating a CDN HIT with correct caching.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
Vary: Accept-Encoding

Separates encoding variants.

This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.

02 / YOUR TURN

Try it yourself first.

Does Vary: Accept-Language cover language chosen by cookie?

Show the solution and explanation
Worked solution
Cache key must reflect actual selection inputs

No; design for the actual selection input or use private/no-store policy.