Calling an LLM or API with the same input twice is wasteful, but caching forever serves stale results. A TTL cache remembers results for a limited time.
Implement a decorator factory ttl_cache(seconds, clock=time.monotonic):
clock() - stored_at < seconds. After that, call the function again and refresh the entry.cache_clear() (empties the cache) and cache_info(), returning a dict {"hits": h, "misses": m, "size": n}.functools.wraps.