TTL cache function.