TapCub is live — analytics, insights and live chat, free on one platform
Glossary

Cache TTL: what time to live means in browser and CDN caches

Cache TTL is how long a cache may reuse a stored copy before checking the source. Where it is set in browsers, CDNs and DNS, how age is counted, and how TTL length changes hit rate.

Lin Zhou Reviewed by Emma Collins Also called time to live Last updated Dec 3, 2026 Glossary

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.

MomentTime in the browserCurrent ageRemaining freshnessState
10:10, response arrives with Age: 6000 s600 s3,000 sFresh
10:552,700 s3,300 s300 sFresh
11:053,300 s3,900 s0 sStale, 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 layerWhere the TTL comes fromWho can shorten it early
Browser (private cache)Cache-Control: max-age, or Expires minus DateThe 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 overrideYou, through a purge
DNS resolverThe TTL field on each DNS recordNobody remotely; you wait for it to run out
Application cacheThe expiry your code sets on a key, such as EXPIRE in RedisYour code, by deleting the key
No explicit lifetime in HTTPHeuristic freshness chosen by the cacheAdd 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):

  1. 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.
  2. At the move, change the address. Keep the old server answering.
  3. After the change, resolvers that honor TTL pick up the new address within about 300 seconds. Local caches can take longer.
  4. 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.

TTLExpected requests served after each missExpected hit rate
60 s0.19%
300 s0.533%
1 hour686%
1 day14499.3%
7 days1,00899.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):

FileHeaderWhy
app.3f9c2a.cssCache-Control: public, max-age=31536000, immutableThe hash changes when the content changes, so a new version has a new URL
/pricing HTMLCache-Control: max-age=300The URL stays the same, so a change must show within five minutes
Product images with stable URLsBrowser 1 hour, CDN 7 days with purge on updateThe 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.

TermWhat it isHow it relates to TTL
max-ageA response directive in secondsThe usual way to state the TTL in HTTP
s-maxageThe same, for shared caches onlyOverrides max-age at a CDN or proxy
ExpiresAn absolute date and timeGives the TTL as Expires minus Date; ignored for freshness when max-age is present
stale-while-revalidateAn extension from RFC 5861A grace window after the TTL in which the stale copy may be served while a new one is fetched
no-cacheA directive that requires validation before reuseClose to a TTL of zero, though the copy is still stored
Retention or evictionHow long the cache keeps the object at allCan 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:

  1. Mark the change. Add a note on the release date in Configuration › Annotations so the trend has a reference point.
  2. 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.
  3. 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.
  4. 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

Was this explanation clear?

We use your answers to fix and expand this page.

Lin Zhou

Product Experience Specialist

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

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

What is a good cache TTL?

It depends on whether the URL changes with the content. Versioned asset files can carry a year. HTML at a fixed address usually gets seconds to minutes. Files you can purge at a CDN can live for days there while browsers keep them for a shorter time.

Is TTL the same as max-age?

In HTTP, max-age is the common way to state the TTL. A shared cache prefers s-maxage when present, and falls back to Expires minus Date when neither directive exists. TTL is the general idea and also applies to DNS records and application caches.

What happens when the TTL expires?

The copy becomes stale. A cache normally revalidates it with the origin before reusing it; if the content is unchanged, the origin can confirm that and the copy is fresh again. With stale-while-revalidate, the old copy may be served while the check runs.

How long does a DNS TTL change take to apply?

Resolvers that already cached the record may keep it until the old TTL runs out. If the old value was 86,400 seconds, lower it at least 24 hours before you change the address. After the change, a 300-second TTL means most resolvers update within minutes.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics