Description
src/cache.ts stores invoice data indefinitely with no expiry. Once an entry is written it stays forever, causing stale data to be served long after an invoice changes state on-chain. This issue adds TTL (time-to-live) support so entries are automatically evicted after a configurable duration.
Acceptance Criteria
Context
- Target file:
src/cache.ts
- Do not add any new dependencies — use
Date.now() only
- All existing tests in
src/__tests__/ must continue to pass
Description
src/cache.tsstores invoice data indefinitely with no expiry. Once an entry is written it stays forever, causing stale data to be served long after an invoice changes state on-chain. This issue adds TTL (time-to-live) support so entries are automatically evicted after a configurable duration.Acceptance Criteria
Cacheclass accepts an optionalttlMs: numberconstructor argument (default: no expiry — backward compatible)set()records the write timestamp alongside the valueget()returnsundefinedand deletes the entry ifDate.now() - writeTime > ttlMshas()also respects TTL — returnsfalsefor expired entriespurgeExpired()method removes all expired entries in one sweepttlMsis not setpurgeExpiredremoves only expired entries,has()returns false for expiredContext
src/cache.tsDate.now()onlysrc/__tests__/must continue to pass