-
Notifications
You must be signed in to change notification settings - Fork 81
Implement pluggable LRU in-memory cache adapter #323
Copy link
Copy link
Closed
Labels
GrantFox OSSGrantFox Open Source Sponsorship program tagGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesIssue may qualify for a reward upon successful completion per campaign rulesThird CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsOfficial FWC26 campaign issue — eligible for campaign scoring and rewards
Description
Activity
Metadata
Metadata
Assignees
Labels
GrantFox OSSGrantFox Open Source Sponsorship program tagGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesIssue may qualify for a reward upon successful completion per campaign rulesThird CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsOfficial FWC26 campaign issue — eligible for campaign scoring and rewards
Difficulty: Intermediate
Type: Feature
Recommended labels (if available in this repo):
enhancement,caching,sdkBackground
docs/cache-adapters.mddocuments the pluggable caching interface, and the roadmap indocs/CAMPAIGN_TASKS.mdlists an LRU cache adapter as a planned-but-not-implemented feature. Currentlyexamples/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
LruCacheAdapterimplementing the cache adapter interface defined insrc/cache/cache.types.ts, usable asnew 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 theCacheAdapterinterface. Add configurablemaxEntriesandttlMs. Wire it as the SDK's default adapter when no adapter is explicitly configured, matching the pattern implied indocs/cache-adapters.md.Acceptance Criteria
LruCacheAdapterclass implements the existingCacheAdapterinterface without modifying the interface itselfdocs/cache-adapters.mdupdated with usage examplepnpm test:runpassesLikely Affected Files/Directories
src/cache/cache.types.tsdocs/cache-adapters.mdexamples/redis-cache-adapter/src/index.ts