Design and Implement a TTL Cache Library
Design a small in-memory cache library whose entries expire predictably after a caller-supplied time to live.
Design and implement a library for a TTL-based caching system, including clear classes and design patterns. For this exercise, assume a single-process, in-memory generic key/value cache. The caller supplies a positive TTL to put(key, value, ttl).
get(key) returns the live value or a missing result, and an entry is unavailable once now is greater than or equal to its expiration deadline. Updating an existing key replaces its value and starts a new TTL from the update time.
Also provide invalidate(key), clear(), and a bounded purgeExpired() operation; access-time expiration checks remain responsible for never returning expired data. Time comes from an injectable monotonic clock so boundary behavior is deterministic and testable.
Keep the core implementation single-threaded, with concurrency as a focused follow-up. Persistence, distributed coherence, read-through loading, and capacity eviction are out of scope.
Running code is not required in the interview setting, but provide coherent implementation-level code or precise pseudocode and focused tests.