Calculate cache TTL and expiration scenarios with freshness analysis. Part of the DevTools Surf developer suite. Browse more tools in the Calculators collection.
Use Cases
Calculate optimal TTL for API responses based on data change frequency
Design Cache-Control headers for static vs dynamic content
Estimate cache invalidation cost at different TTL values
Debug stale cache issues by modeling freshness windows
Tips
Set the TTL based on your data change frequency — static assets can use 1 year (31,536,000 seconds) while database results may need 60-300 seconds
Use the freshness analysis panel to see at what TTL percentage staleness risk becomes material for your use case
The stale-while-revalidate configuration shows how to serve cached data while refreshing in the background — reducing perceived latency without increasing origin load
Fun Facts
HTTP caching headers (Expires, Cache-Control) were introduced in HTTP/1.0 (1996) and extended in HTTP/1.1 (1999). The max-age directive in Cache-Control is now the preferred way to set TTL, superseding the Expires header.
CDN cache hit ratios for popular static assets can exceed 99%. Netflix's CDN (Open Connect) serves over 95% of traffic from cache — reducing the data Netflix must transmit from its origin by roughly 20:1.
The concept of a TTL was borrowed from network routing: IP packets have a TTL field (maximum 255 hops) to prevent routing loops. DNS records adopted the same concept for controlling how long resolvers cache answers.
FAQ
What is the difference between TTL and max-age?
TTL is the generic concept: the duration a cached item is considered fresh. max-age is the specific HTTP Cache-Control directive that sets TTL in seconds. They mean the same thing in the HTTP context.
Should I use Expires or Cache-Control max-age?
Always prefer Cache-Control max-age — it is relative to request time and more reliable. Expires uses an absolute date that can desync if the server clock differs from the client. Both can coexist; max-age takes precedence.
What is stale-while-revalidate?
A Cache-Control extension that lets a CDN serve a stale cached response immediately while asynchronously fetching a fresh copy. Users get fast responses even during cache refreshes, at the cost of serving briefly outdated data.