Skip to content

Implement LRU eviction policy for the SDK in-memory cache #397

Description

@Kingsman-99

Overview

The current cache evicts entries only by TTL. Under high usage with many unique keys, the cache grows unbounded until TTL expires. Add LRU (Least Recently Used) eviction to cap memory usage.

Acceptance Criteria

  • StellarSplitSDK({ cache: { maxEntries: 500 } }) config option
  • When maxEntries is reached, the least recently accessed entry is evicted before adding a new one
  • LRU order updated on every cache hit (read counts as access)
  • sdk.getCacheStats() adds evictions: number to the existing stats
  • LRU and TTL work together: an entry can be evicted by either mechanism
  • maxEntries defaults to 1000 when cache is enabled; 0 means no LRU cap
  • Implementation uses a Map + doubly-linked list for O(1) get/put
  • Unit tests: fill cache to maxEntries + 1, verify oldest entry evicted; verify LRU order respected

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions