advanced24 min studyLesson 206 in Engineering

A resource can have multiple representations and cache identities

Reason about media types, content codings, quality values, Vary matching, and the capacity cost of serving correctly selected representation variants.

On this page

What you’ll understand

  • Separate resource identity from representation format and content coding.
  • Apply explicit client preferences to a stated set of available variants.
  • Explain how Vary affects matching without replacing privacy or authorization policy.

One resource might be represented as JSON or HTML, in different languages, with different content codings. Choosing among them is a protocol decision, not merely a file-extension convention. The response needs to describe what it actually contains, and a cache needs enough selection information to avoid serving the wrong variant later. Work through preference, selection, metadata, and matching as separate steps rather than assuming one URL always names one immutable byte string.

Describe the representation that was selected

A resource is the conceptual target identified by a request; a representation conveys its current or intended state in a particular form. Content-Type identifies the representation's media type, while Content-Encoding describes a coding applied to its representation data, such as gzip. These are different from transfer framing. A JSON representation compressed with gzip is still JSON after decoding. Charset rules depend on the media type rather than an assumption that every byte sequence is text. Clients should verify the response's actual metadata instead of treating their own Accept request as proof of what arrived.

Proactive negotiation can consider request fields such as Accept, Accept-Language, and Accept-Encoding along with the server's available representations and selection policy. Quality values express relative client preferences within their defined matching rules; q=0 excludes the matching item under those rules. They are not measured probabilities or global utility scores that can be multiplied indiscriminately across every field. Server availability and policy still matter, and unspecified preferences have specification-defined behavior. A useful example must state its available variants and tie-breaking assumptions rather than claim that one abbreviated header determines every possible server's choice.

0≤qi≤1,qi=0⇒matching item is unacceptable0\leq q_i\leq1,\qquad q_i=0\Rightarrow\text{matching item is unacceptable}
q_i is a dimensionless HTTP quality value under the relevant negotiation field's matching and specificity rules. It expresses preference, not delivery probability, and does not independently determine the server's full selection policy.↔ Scroll wide equations horizontally.

Vary records selection dimensions for later matching

A Vary response field identifies request fields that influenced representation selection so caches can match subsequent requests appropriately. If Accept-Language selects the content, a cache must not assume every request for the URL can reuse the stored language variant. Matching follows field-specific equivalence and the cache's rules, not necessarily raw byte-for-byte header string equality. Vary: * indicates that a cache cannot determine suitability from ordinary matching alone and requires origin participation under the specification. A proxy must not generate that wildcard. Selection metadata belongs with the stored response and its validator.

Vary is not an access-control mechanism. A response influenced by user identity may need private storage restrictions, no-store, or other explicit shared-cache permissions depending on its contract; adding a user-related field to Vary is not a universal safe-public-caching recipe. Avoid leaking personalized data through an incomplete key or an overbroad reuse rule. Conversely, adding unnecessary high-cardinality selection fields can fragment the cache and reduce useful reuse. Optimize only after preserving correct selection and isolation: serving the wrong user's or wrong language's bytes quickly is still a failed request.

Nvariants≤Nmedia Nlanguage NcodingN_{\rm variants}\leq N_{\rm media}\,N_{\rm language}\,N_{\rm coding}
This upper bound counts a finite independently combinable representation catalog. Counts are dimensionless and not every combination need exist; actual cache cardinality can also depend on URI, method, policy, and additional selection dimensions.↔ Scroll wide equations horizontally.

Measure correctness and reuse together

A representation rollout can change validators, compression, content length, and decoding cost even when the conceptual resource stays the same. Test both old and new clients, selected variants, absent preference fields, unacceptable choices, and shared-cache reuse paths. A strong validator must meet its identity requirements for the representation being validated; do not carry a byte-identity claim across transformed bytes without checking those rules. Record response media type, content coding, Vary dimensions, cache outcome, and user-visible decoding errors so a hit-rate improvement does not conceal mismatched content or newly expensive decompression.

The cache lab models variant-identity pressure only as a toy address cycle. Reset, explicitly set BOTH C=4 and s=4, predict twelve hits among N=16 initial requests, then Play or Step. Reset and re-set BOTH C=4 and s=2; predict zero hits because eight distinct addresses cycle through four slots. Edits retain time and recompute the deterministic trace from empty; each comparison needs Reset. The addresses are illustrative identities, not actual Accept values, and the lab has no Vary or freshness logic. Use it to explain capacity pressure from more identities without treating fewer variants as permission to select incorrectly.

Count variants before choosing a cache budget

A fictional service independently offers two media formats, three languages, and two content codings for one resource. Assume every combination exists, each stored variant uses 50,000 bytes, and metadata is ignored.

  1. Multiply independent choices: 2×3×2=12 variants. These are different stored representations, not twelve different conceptual resources.

  2. Multiply by payload size: 12×50,000=600,000 bytes for one copy of every variant. A 300,000-byte payload budget can hold only six equal-sized variants at once.

  3. If content selection depends on all three request dimensions, cache matching must preserve those distinctions under the applicable rules. Reducing the key to only the URL would save apparent entries by returning incorrect content, not by improving cache design.

The result

Correct variant selection costs capacity. Representation policy and cache budgeting must be designed together without collapsing required identity distinctions.

Explore the model

Interactive lab

Interactive lab · cache

More identities can exhaust the same cache

For EACH run Reset, re-set BOTH C and s, predict, then Play or Step. At N=16/t=0, (4,4) yields twelve hits over four cyclic identities; (4,2) yields zero over eight identities. Edits retain t and recompute from empty. This fixed modulo-16 LRU trace implements neither HTTP negotiation nor Vary, freshness, or authorization.

More identities can exhaust the same cacheA fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Current readings: Hits / requests: 0 / 16; Hit rate: 0%; Address-stream period: 16 addresses. All parameters are adjustable with the labeled controls below.Fully associative LRU cache after 16 deterministic requests: 0 hits and 16 misses.Most recent 16 requestsaddress = i × 3 mod 160M3M6M9M12M15M2M5M8M11M14M1M4M7M10M13MCurrent cache order · oldest → newest471013Latest address 13 · miss: inserted as newestToy address stream · period 16 · starts empty
Cached addressMiss / evictionMost recent request
Hits / requests
0 / 16
Hit rate
0%
Address-stream period
16 addresses
t = 0 s

A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAdditional variant identities can reduce capacity reuse, but key correctness must come before hit-rate optimization.

Check your understanding

A service selects English or French content using Accept-Language. What is a necessary cache-design concern?

Try it yourself

A server offers only JSON and XML. A client's applicable media preferences assign JSON q=0.8, XML q=0, and HTML q=1. Under a policy choosing the highest acceptable available type, what is selected and why?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Filter by availability and acceptability before comparing the remaining quality values.

Compare with the solution

JSON is selected: HTML has the highest listed preference but is unavailable, and XML is unacceptable because its applicable q is zero. This answer depends on the stated offers and selection policy; the actual response must still declare its chosen Content-Type rather than leaving the client to infer it.

Take it with you

  • Resource identity, media type, content coding, and framing describe different concepts.
  • Negotiation preferences need availability and field-specific selection rules.
  • Correct Vary matching preserves representation distinctions without replacing privacy controls.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.