Design an In-Memory Read-Through Cache
Model a reusable application cache with loading, expiration, invalidation, and bounded capacity.
For this exercise, assume an application needs a reusable in-memory key/value cache in front of an authoritative data source. A caller can get a key through a supplied loader, put a value with a positive time to live, invalidate a key, or clear the cache.
Get returns a live cached value when present; otherwise it invokes the loader once for that request; the loader returns either a value with a positive time to live or a failure, and a successful result is cached with that time to live. Loader failures are returned without installing a value.
Expired entries are never returned, and invalidation makes a prior value immediately unavailable. The cache has a positive maximum entry count and evicts one resident entry when a new insertion would exceed capacity; the eviction choice is a design decision. Design the object model, contracts, and interaction flows.
One process and an injectable monotonic clock are in scope; persistence, networking, and cross-process coherence are out of scope. Do not implement the component.