Skip to content

Implement pluggable LRU in-memory cache adapter #418

Description

@Lakes41

Difficulty: Intermediate
Type: Feature
Recommended labels (if available in this repo): enhancement, caching, sdk

Background

docs/cache-adapters.md documents the pluggable caching interface, and the roadmap in docs/CAMPAIGN_TASKS.md lists an LRU cache adapter as a planned-but-not-implemented feature. Currently examples/redis-cache-adapter/ shows how to plug in Redis, but there is no lightweight in-memory default for consumers who don't want an external cache dependency.

Problem

Consumers who don't need Redis (e.g. simple Node scripts or short-lived edge functions) have no first-party in-memory cache option and must either write their own adapter or run without caching entirely, hurting default performance.

Expected Outcome

A new LruCacheAdapter implementing the cache adapter interface defined in src/cache/cache.types.ts, usable as new LruCacheAdapter({ maxEntries, ttlMs }), with TTL-based expiry.

Suggested Implementation

Implement a doubly-linked-list-backed or Map-based LRU (insertion-order eviction is acceptable if a full O(1) LRU is out of scope) honoring the CacheAdapter interface. Add configurable maxEntries and ttlMs. Wire it as the SDK's default adapter when no adapter is explicitly configured, matching the pattern implied in docs/cache-adapters.md.

Acceptance Criteria

  • New LruCacheAdapter class implements the existing CacheAdapter interface without modifying the interface itself
  • Supports configurable max size and TTL-based expiry
  • Unit tests cover eviction order, TTL expiry, and get/set/delete/clear behavior
  • docs/cache-adapters.md updated with usage example
  • pnpm test:run passes

Likely Affected Files/Directories

  • src/cache/cache.types.ts
  • docs/cache-adapters.md
  • examples/redis-cache-adapter/src/index.ts

Metadata

Metadata

Labels

GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewards

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions