INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

Topic lessonTopic: CloudFront: delivery, caching and 403 errors

CloudFront caching explained: cache keys, TTLs and content updates

Requests to the same URL should not always share the same response. A CloudFront cache key distinguishes reusable responses, while TTL settings govern freshness. Follow a fictional public catalog to separate language mix-ups from content that remains cached after an update.

What you will learn

Choose the response-defining inputs for a cache key, trace reuse and expiry, and distinguish versioned filenames from invalidation.

Prerequisite

An origin is the source, such as a server or S3. A cache reuses a stored response. Query parameters follow the question mark in a URL. This lesson makes no AWS requests and provisions no paid resources.

Decide which requests can share a response

A cache key identifies the stored response to look up. A hit requires an available, reusable matching entry. Include language when it changes the representation. Including tracking parameters that do not change the response fragments reuse.

One key, two outcomes depending on a reusable entry
One key, two outcomes depending on a reusable entry1: Look up key — An eligible entry is available — Cache hit. 2: Look up key — No reusable entry is available — Contact origin12Look up keyCache hitContact originOne key, two outcomes depending on a reusable entry1: Look up key — An eligible entry is available — Cache hit. 2: Look up key — No reusable entry is available — Contact origin12Look up keyCache hitContact origin
  1. Look up key → Cache hitAn eligible entry is available
  2. Look up key → Contact originNo reusable entry is available
Look up key
For the public-catalog example
Cache hit
Reuse the available entry
Contact origin
For a miss or an expired entry

Separate forwarding from key selection

A cache policy selects headers, cookies and query parameters for the key and supplies TTL settings. Key values are forwarded to the origin. An origin request policy can forward additional inputs without putting them in the key. Forwarding therefore does not, by itself, partition cached responses.

Public catalog: distinguish representation inputs
InputRole in this exampleKey treatment
Path /catalog.jsonSelects the resourceDistinguish it
lang=en / lang=jaChanges the response languageDistinguish it
utm_sourceAttribution only; identical responseExclude in this example

C1: trace which version is returned

C1 is a reading model with one cache location. It starts empty, keys by path plus lang and has an effective TTL of 60 seconds from retrieval. Only GET requests occur; there is no eviction, failure, browser cache or stale-response reuse directive. Forwarded utm_source never changes the body. Times and responses below are stipulated for this example.

C1: an origin update does not immediately remove a cached copy
TimeEventResult under C1
0 sRequest lang=enMISS: retrieve en-v1; retain for 60 seconds.
20 sRequest lang=en with a different utm_sourceHIT: same key, en-v1.
25 sRequest lang=jaMISS: retrieve ja-v1 under another key.
30 sOrigin English version changes to en-v2No request occurs; the stored en-v1 remains.
45 sRequest lang=enHIT: en-v1 is still fresh.
61 sRequest lang=enExpired: origin returns 200 with en-v2, as stipulated.

Expiry is not an automatic push of new content. A subsequent request can trigger origin validation; an unchanged representation can yield 304, while changed content can yield 200 with a new body. C1 fixes the latter response rather than predicting every live request.

For comparison, C2 omits lang from the key while the origin varies the body by language. A Japanese request matching an English cached entry can reuse the English body. A shorter TTL does not fix an incorrect partition. First align the key with the inputs that change the response.

A TTL is not a guaranteed update schedule

TTL (Time To Live) expresses a freshness lifetime. CloudFront combines minimum, maximum and default TTL settings with origin freshness headers such as Cache-Control. The default applies when the relevant origin freshness information is absent.

Separate example T1: minimum 10 s, maximum 120 s, default 30 s
Origin directiveEffective TTL in T1Reason
max-age=300120 sBounded by the maximum.
max-age=510 sRaised to the minimum.
No relevant freshness header30 sUses the default.

Plan the name, references and copies involved in an update

Three update mechanisms to distinguish
MechanismWhat changesWhat still needs checking
Overwrite the same origin pathOrigin bodyFresh stored copies do not vanish immediately.
app.v1.js → app.v2.jsA different filenameUpdate HTML references too; distinct from S3 Versioning.
CloudFront invalidationInvalidates selected CloudFront copiesDoes not clear every browser or intermediary cache.
  1. Check the key against the inputs that change the body.
  2. Identify changed files, references and a recovery plan.
  3. Choose freshness, versioned filenames and any necessary invalidation.
  4. Separate origin, CloudFront and browser observations when locating an old copy.
  5. Keep personalized responses outside the public-cache example.

Check the key, time and update mechanism

Choose an option to see the result and explanation.

How should C2 avoid reusing an English response for a Japanese request?
Read the answer and reason

Answer: Include response-defining lang in the key · The origin varies the body by language, so the key must distinguish that variation.

Which body is returned at 45 seconds for lang=en in C1?
Read the answer and reason

Answer: en-v1 · The copy stored at 0 seconds remains fresh for 60 seconds; the origin update alone does not remove it.

What is the effective TTL when T1 receives max-age=300?
Read the answer and reason

Answer: 120 seconds · The supplied 300 seconds is bounded by the configured 120-second maximum.

Does a CloudFront invalidation also clear every user’s browser cache?
Read the answer and reason

Answer: No; distinguish the cache layers · Browser or intermediary copies may remain. Plan names, references and freshness headers across layers.

Check, then explain in your own words

  1. Trace C1 at 0, 20, 25, 45 and 61 seconds per key.
  2. Explain why lang differs from utm_source.
  3. Apply the minimum, maximum and default in T1.
  4. Explain versioned filenames and the scope of CloudFront invalidation.
Check your understanding: What should you separate when an origin update still yields an old response?

Separate the cache key, effective freshness and the layer holding the old copy.

An incorrect response partition calls for a different fix from reusing a still-fresh copy.

Sources and conditions checked

The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.