What is TTL in CDN caching?
TTL, or time to live, is how long a cache keeps a response fresh before it must revalidate or refetch it. In HTTP it comes from max-age or s-maxage.
TTL, or time to live, is how long a cache treats a stored response as fresh. In HTTP terms it is the freshness lifetime, set by `s-maxage`, `max-age` or Expires. When the TTL runs out, the response becomes stale and the cache must revalidate or refetch it, unless a stale directive allows otherwise.
CDN-Cache-Control: max-age=86400 # edge TTL: 1 day
Cache-Control: max-age=60 # browser TTL: 1 minuteMost CDNs distinguish an edge TTL, for their own cache, from a browser TTL, and let rules override the origin headers. Amazon CloudFront, for example, combines the origin's headers with minimum, maximum and default TTLs configured on the distribution.
- A TTL is a maximum, not a guarantee. A PoP can evict a rarely requested object before its TTL ends.
- A long TTL raises the cache hit ratio, and a purge on deploy keeps it from serving outdated pages.
- The `Cache-Status`
ttlparameter reports how much freshness is left.
Related terms
References
- RFC 9111: HTTP Cachinghttps://www.rfc-editor.org/rfc/rfc9111
- Amazon CloudFront: Manage how long content stays in the cachehttps://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html
- Cloudflare: Default cache behaviorhttps://developers.cloudflare.com/cache/concepts/default-cache-behavior/
Warm your cache after every deploy
sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.