Caching and Content Delivery Optimization
Cache mechanics
Edge caching decisions depend on cacheability (method, status code, response headers) and freshness (TTL from Cache-Control/Expires, or heuristic/default TTLs). Key headers: Cache-Control (max-age, s-maxage, no-cache, no-store, private, public), Expires, ETag/Last-Modified, Vary, and Age. Understand TTL override at the edge, cache keys (hostname, path, query string, selected headers/cookies), and purge/invalidation (single object, CP code, or tag-based). Tiered distribution adds a parent layer to raise hit ratio and shield origin.
Traps
no-cachemeans revalidate before use, not do not store;no-storeis the do-not-store directive.privateprevents shared-cache storage, so an edge cannot cache it even with a long TTL.- Query strings and cookies in the cache key fragment the cache - high cardinality destroys hit ratio.
- A long browser TTL on a fingerprinted asset is good; on HTML it delays updates.
- Purge is not instant everywhere and does not fix a bad cache key.
Rule of thumb
Aim for long TTLs plus content hashing for static assets (effectively immutable), short or revalidated TTLs for HTML, and a minimal cache key. Every field you add to the key can multiply stored variants.
Worked example
A CSS file served with Cache-Control: max-age=31536000, immutable and a hashed filename can be cached for a year at edge and browser. A new release publishes a new hash, so no purge is needed. HTML stays max-age=60 with revalidation.