Highlights

Contents

Part II
02

TTL and Cache-Control

We decide when a retained response may be reused without contacting its source. Stored bytes do not become fresh again merely because another cache received them. We will compute age, distinguish shared and private policies, revalidate conditionally, and bound stale service.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Edges, origins, hits andmisses2TTL and Cache-Control3Invalidation andversioned URLs4Pull vs push CDN andshielding5Signed URLs and privatedelivery6Geographic routing7Video and image delivery8Case study: private videodelivery

#Section 5TTL is a freshness rule, not guaranteed retention

A clip response is stored, then removed early because the edge needs space. A score response is still stored but too old to use without validation. Time to live, or TTL, commonly describes a freshness interval in this context; it does not guarantee that the cache will retain an entry for that whole period.

HTTP caches compare a response’s current age against its allowed freshness lifetime using protocol rules and policy. A fresh entry can be reused without ordinary origin validation, subject to other request conditions. An expired retained entry can still help through conditional validation or a permitted stale mode; absent bytes cannot.

STORED ASKS "ARE THE BYTES HERE?"; FRESH ASKS "MAY THIS REQUEST USE THEM?"STORED ASKS "ARE THE BYTES HERE?"; FRESH ASKS "MAY THIS REQUEST USE THEM?"retentioneviction can remove bytes earlyfreshnessage vs lifetime decides reuse
Figure 14.5Freshness versus storage residency. A chosen lifetime is not a residency guarantee.

Check the CDN’s minimum and maximum configured TTL as well as origin directives. Configuration can constrain what the edge does. Heron should use a deliberate immutable-media policy and a separate score freshness policy because score updates and immutable video bytes change differently.

#Section 6Compute current age across cache layers

An edge receives a response whose corrected initial age is an illustrative 120 seconds. The allowed freshness lifetime is 300 seconds. Only 180 fresh seconds remain; assigning a new 300-second lifetime from local receipt would forget the age already spent upstream.

In this simplified trace, residence adds directly to corrected initial age. After 240 seconds at the edge, current age is 360 and the response is 60 seconds past its 300-second lifetime. Real HTTP corrected age includes the protocol’s response-delay and clock rules, so use the standard or implementation rather than only wall-clock subtraction.

acurrent=ainitial+tresident.a_{\text{current}}=a_{\text{initial}}+t_{\text{resident}}.

Read this as current age equals corrected initial age plus time resident in this cache. Here ainitiala_{\text{initial}} is already corrected for upstream and response timing; tresidentt_{\text{resident}} is elapsed local residence. RFC 9111 defines the complete freshness and age calculation.

A CACHED RESPONSE INHERITS AGE; ARRIVAL DOES NOT RESET ITS CLOCKA CACHED RESPONSE INHERITS AGE; ARRIVAL DOES NOT RESET ITS CLOCK0 s120 s300 s360 sarrives already 120 s old240 s residence → 360 s current agestale300 s lifetime − 120 s initial age = 180 s initially fresh
Figure 14.6Simplified age trace after corrected initial age is known. Full HTTP age calculation includes response timing rules.

#Section 7Cache-Control, private caches, and shared caches

Heron wants a public asset to stay fresh in a browser for an illustrative 60 seconds but in a shared CDN for 300. max-age and s-maxage can express distinct HTTP freshness rules for those scopes, subject to the other directives and actual cache configuration.

A private cache is dedicated to one user, while a shared cache can reuse responses across users. private prevents ordinary shared storage of a response under its rules. no-store forbids storing under the directive’s scope. no-cache means reuse requires successful validation; it does not simply mean never retain bytes.

FOUR DIRECTIVES, FOUR DIFFERENT RULES ABOUT STORING AND REUSINGFOUR DIRECTIVES, FOUR DIFFERENT RULES ABOUT STORING AND REUSINGmax-age=60browser may reuse for 60 ss-maxage=300shared caches may reuse for 300 sno-cachemay store; must validate firstno-storemust not store at all
Figure 14.7HTTP directive meanings. Actual request and response directives and CDN policy must be evaluated together.

Personalized responses need careful scope. A public score representation may be reusable across authorized viewers, while a personal account page must not become a shared public response. Some authenticated responses can be cached under explicit permitted rules, but a design should justify that choice rather than treating credentials as irrelevant.

#Section 8Conditional validation and stale windows

An expired entry has an ETag for its exact representation. The edge sends a conditional request such as If-None-Match. If the origin reports that representation unchanged, a 304 response permits the cache to update the relevant metadata and reuse retained content under the protocol rules, avoiding retransmission of the full body.

Stale-while-revalidate permits a bounded stale reuse while refresh happens, and stale-if-error permits selected stale reuse during specified failures when allowed. RFC 5861 defines these extensions. They are explicit policy, not permission to serve arbitrarily old or unauthorized content.

EXPIRED BUT UNCHANGED: A 304 LETS THE EDGE REUSE THE BODY IT ALREADY HOLDSEXPIRED BUT UNCHANGED: A 304 LETS THE EDGE REUSE THE BODY IT ALREADY HOLDSvieweredgeoriginGET (expired copy)If-None-Match: "v12"304 Not Modifiedretained bodyonly headers cross the origin link; the full body does not
Figure 14.8Conditional validation path. The validator refers to the selected representation, not every response at the same path.

With lifetime 300 seconds and a 30-second stale-if-error allowance, illustrative age 320 is 20 seconds stale and fits. Age 340 is 40 seconds stale and exceeds that allowance. Permission, deletion, and directives that require validation can impose tighter conditions; stale service cannot weaken them.

LIFETIME 300 S + 30 S STALE-IF-ERROR: AGE 320 MAY BE SERVED, AGE 340 MAY NOTLIFETIME 300 S + 30 S STALE-IF-ERROR: AGE 320 MAY BE SERVED, AGE 340 MAY NOTfresh+30060120180240300360 sage 320age 340permission and deletion still apply inside the window
Figure 14.9Illustrative age comparison. Reuse must also satisfy the chosen response and access policy.