What is TTL
TTL (Time To Live) is the amount of time a piece of data remains valid before it must be discarded or refreshed. It is used in caching, DNS, and network protocols.
How it works
When data is cached, it is stored with a TTL — for example, 60 seconds. After 60 seconds, the entry expires. The next request triggers a fresh fetch from the source.
In DNS, the TTL on a record tells resolvers how long to cache the IP address. A TTL of 300 seconds means resolvers cache the record for 5 minutes before querying the authoritative server again.
In HTTP, Cache-Control: max-age=3600 sets a TTL of one hour for the browser and intermediate caches.
Why it matters
TTL is the simplest cache invalidation strategy. Short TTLs mean fresher data but more origin load. Long TTLs mean less load but staler data. Choosing the right TTL is a tradeoff between freshness and performance that depends on how quickly the underlying data changes and how much staleness is acceptable.