A bounded, TTL-expiring, in-memory key-value cache. Entries live for a configured time-to-live and the cache evicts its least-recently-used key when capacity is reached. Great for practicing injected clocks, explicit sweeps, and generic domain types with test data builders.
- Test Data Builders —
CacheBuilder().WithCapacity(n).WithTtl(...).WithClock(clock).Build()returns a(Cache, Clock)tuple so tests advance time. - Injected Clock —
Clockis a collaborator interface;FixedClockin tests lets TTL expiry tests drive the behavior deterministically. - Explicit Sweep —
evictExpired()mirrorslibrary-management'sExpireReservationsandvideo-club-rental'sMarkOverdueRentals. Expiry is a consequence of time passing, not of a user action; the sweep is the production caller's responsibility. - Domain Exception Types —
CacheCapacityInvalidExceptionandCacheTtlInvalidExceptionname the rejection, rather than throwing a genericError/ValueError. - Generic Value Type —
Cache<V>(C#/TS) /Cache[V](Python) keeps the cache polymorphic without leaking concrete types into the domain.
See SCENARIOS.md for the shared specification.