Quick answer
Cache TTL (time to live) is how long a cache may reuse a stored copy before checking the source again. In HTTP it is the freshness lifetime: a response is fresh while its age is below it. Browsers, CDNs, DNS resolvers and application caches each have their own.
Formula: Fresh while current age < TTL; remaining freshness = TTL − current age
What is cache TTL?
Cache TTL (time to live) is the length of time a cache may reuse a stored copy before it has to check back with the source. A browser holding a stylesheet, a CDN edge holding an image, a DNS resolver holding an IP address and an application cache holding a database result all work from the same idea: this copy is good for a set number of seconds.
HTTP calls this the freshness lifetime. RFC 9111 defines a response as fresh while its age has not exceeded that lifetime and stale once it has. A fresh copy can be served without contacting the origin server. A stale one is not necessarily thrown away; a cache normally asks the origin whether it is still valid before using it again.
The freshness rule and age
Fresh while current age < TTL. Remaining freshness = TTL − current age.
The part people miss is that age does not start when your cache receives the copy. It starts when the origin generated or last validated the response. A shared cache passes the time already spent in the Age header, and the next cache adds its own holding time:
current age = age on arrival + time stored since arrival
This ignores network transit, which RFC 9111 also accounts for. Sample data: a CDN fetched a file with Cache-Control: max-age=3600 at 10:00, and a browser receives it from the CDN at 10:10.
| Moment | Time in the browser | Current age | Remaining freshness | State |
|---|---|---|---|---|
10:10, response arrives with Age: 600 | 0 s | 600 s | 3,000 s | Fresh |
| 10:55 | 2,700 s | 3,300 s | 300 s | Fresh |
| 11:05 | 3,300 s | 3,900 s | 0 s | Stale, revalidate |
If you read only max-age=3600 you would expect the browser copy to last until 11:10. It goes stale at 11:00.
Where cache TTL is set
| Cache layer | Where the TTL comes from | Who can shorten it early |
|---|---|---|
| Browser (private cache) | Cache-Control: max-age, or Expires minus Date | The visitor, by clearing the cache; a CDN purge does not reach it |
| CDN or proxy (shared cache) | s-maxage first, then max-age, then Expires; CDN rules can override | You, through a purge |
| DNS resolver | The TTL field on each DNS record | Nobody remotely; you wait for it to run out |
| Application cache | The expiry your code sets on a key, such as EXPIRE in Redis | Your code, by deleting the key |
| No explicit lifetime in HTTP | Heuristic freshness chosen by the cache | Add an explicit header |
For HTTP, RFC 9111 sets the order: a shared cache uses s-maxage if present; otherwise max-age; otherwise Expires minus Date. When none exists, a cache may guess for some responses. The specification notes that a typical heuristic is 10% of the time since Last-Modified, so a file last changed 20 days ago might be treated as fresh for about 2 days. If that surprises you, set the header yourself. The values to choose for each file type are covered in the Cache-Control header guide.
DNS TTL works the same way with different consequences
In DNS, RFC 1035 describes TTL as the interval a resource record may be cached before it should be discarded, and a value of zero means the record is only for the transaction in progress. RFC 2181 later fixed the range at 0 to 2,147,483,647 seconds.
DNS TTL decides how quickly a change of address or provider reaches visitors. Sample migration plan for a record that currently has a TTL of 86,400 seconds (24 hours):
- At least 24 hours before the move, lower the TTL to 300. Resolvers that cached the old record may keep it for up to the old TTL, so lowering it an hour ahead is too late.
- At the move, change the address. Keep the old server answering.
- After the change, resolvers that honor TTL pick up the new address within about 300 seconds. Local caches can take longer.
- Once traffic on the old server has stopped, raise the TTL again.
Two related rules matter. "Name not found" answers are cached too, with a lifetime taken from the zone's SOA record (RFC 2308). And some resolvers may serve an expired record when the authoritative servers cannot be reached (RFC 8767), so TTL is not a hard cut-off in every failure.
How TTL length trades freshness for hit rate
A longer TTL gives more requests the chance to be answered from cache, and a longer delay before changes appear. A simple model shows the shape. Assume requests for one object arrive at random at an average rate r at a single cache that never evicts it. Each miss is then followed by r × TTL hits on average, so the expected cache hit rate is r × TTL ÷ (1 + r × TTL).
Sample data: one request every 10 minutes.
| TTL | Expected requests served after each miss | Expected hit rate |
|---|---|---|
| 60 s | 0.1 | 9% |
| 300 s | 0.5 | 33% |
| 1 hour | 6 | 86% |
| 1 day | 144 | 99.3% |
| 7 days | 1,008 | 99.9% |
Two lessons follow. Going from one minute to one hour changes everything for a quiet object; going from one day to seven adds almost nothing. And a busy object reaches a high hit rate even with a short TTL: at one request per second, a 60-second TTL already gives about 98%.
Real caches do worse than the model. Cloudflare's documentation separates freshness (the TTL) from retention: an object nobody requests can be evicted to make room long before its TTL ends. Traffic split over many edge locations also lowers the rate each one sees.
Worked example: long TTL for assets and short TTL for HTML
A common pattern pairs two very different lifetimes (sample setup):
| File | Header | Why |
|---|---|---|
app.3f9c2a.css | Cache-Control: public, max-age=31536000, immutable | The hash changes when the content changes, so a new version has a new URL |
/pricing HTML | Cache-Control: max-age=300 | The URL stays the same, so a change must show within five minutes |
| Product images with stable URLs | Browser 1 hour, CDN 7 days with purge on update | The CDN can be purged; browsers refresh within the hour |
31,536,000 seconds is one year. Now the images, with sample measurements: the site served 500,000 image requests a week. With a 1-hour CDN TTL the hit rate was 72%, so 140,000 requests went to the origin. After raising the CDN TTL to 7 days it was 91%, leaving 45,000. That is 95,000 fewer origin requests, a 68% drop. At 180 KB per image, origin transfer falls from about 25.2 GB to 8.1 GB a week.
The price is the purge step. If an image is replaced under the same URL and nobody purges, edges that still hold it can keep serving the old file for up to seven days. Browsers are a separate matter: purging a CDN does not remove copies already stored on visitors' devices.
Cache TTL vs max-age, Expires and stale-while-revalidate
| Term | What it is | How it relates to TTL |
|---|---|---|
max-age | A response directive in seconds | The usual way to state the TTL in HTTP |
s-maxage | The same, for shared caches only | Overrides max-age at a CDN or proxy |
Expires | An absolute date and time | Gives the TTL as Expires minus Date; ignored for freshness when max-age is present |
stale-while-revalidate | An extension from RFC 5861 | A grace window after the TTL in which the stale copy may be served while a new one is fetched |
no-cache | A directive that requires validation before reuse | Close to a TTL of zero, though the copy is still stored |
| Retention or eviction | How long the cache keeps the object at all | Can end earlier than the TTL |
Common mistakes with cache TTL
- A long browser TTL on a URL that never changes. You cannot recall it. Use versioned filenames or keep browser lifetimes short.
- Confusing the CDN setting with the browser header. Some CDNs apply an edge TTL that never appears in response headers. Check both.
- Lowering DNS TTL at the moment of a migration. The old value is already in resolvers.
- Setting identical expiry on many application cache keys. They run out together and the database takes the whole load at once. Add a small random offset.
- Assuming a TTL guarantees a hit. Eviction, cache keys that vary by query string or cookie, and bypass rules all cause misses. The CDN cache guide shows how to read the cache status header.
Checking the effect of a TTL change in TapCub
TapCub does not manage caches and does not read your CDN logs, so hit rate comes from your CDN. What TapCub can show is whether real visitors loaded pages faster after the image change:
- Mark the change. Add a note on the release date in Configuration › Annotations so the trend has a reference point.
- Compare loads. In Monitoring › Performance, pick P75 and read Time to first byte and Largest contentful paint for the days before and after. Break down by page and find the product pages that use those images.
- Split the delay. The loading breakdown separates backend, network and frontend. A lighter load on the origin would show, if at all, in backend time; images served from nearer caches tend to show in Largest contentful paint.
- Check by country and device. If only regions far from your origin improved, that is consistent with edge caching doing the work.
Performance samples come from one full page load at a time, so changes of route inside a single-page app add no new samples. Other releases in the same period also move these numbers, so treat the comparison as evidence rather than proof.
Sources
- IETF, RFC 9111: HTTP Caching (freshness, age calculation,
s-maxage,max-age,Expires, heuristic freshness; checked 2026-12-03). - IETF, RFC 1035: Domain Names, Implementation and Specification (TTL field of DNS resource records; checked 2026-12-03).
- IETF, RFC 2181: Clarifications to the DNS Specification (TTL value range; checked 2026-12-03).
- IETF, RFC 5861: HTTP Cache-Control Extensions for Stale Content (
stale-while-revalidate; checked 2026-12-03). - Cloudflare Docs, Retention vs Freshness (TTL) (eviction versus TTL; checked 2026-12-03).
Was this explanation clear?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Product Experience Specialist
Writes about product experience, practical workflows, and growth, turning complex processes into clear steps for everyday decisions.