Skip to content

Add TTL-based entry expiry to the invoice cache #606

Description

@Kingsman-99

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

  • Cache class accepts an optional ttlMs: number constructor argument (default: no expiry — backward compatible)
  • Each set() records the write timestamp alongside the value
  • get() returns undefined and deletes the entry if Date.now() - writeTime > ttlMs
  • has() also respects TTL — returns false for expired entries
  • A new purgeExpired() method removes all expired entries in one sweep
  • Existing behaviour unchanged when ttlMs is not set
  • Unit tests: entry expires after TTL, entry valid before TTL, purgeExpired removes only expired entries, has() returns false for expired

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions