Skip to content

Feat/lru batch cache eviction#133

Merged
Smartdevs17 merged 5 commits intoSmartdevs17:mainfrom
shaaibu7:feat/lru-batch-cache-eviction
Mar 24, 2026
Merged

Feat/lru batch cache eviction#133
Smartdevs17 merged 5 commits intoSmartdevs17:mainfrom
shaaibu7:feat/lru-batch-cache-eviction

Conversation

@shaaibu7
Copy link
Copy Markdown
Contributor

feat(cache): implement LRU batch eviction

Replaces the single-entry oldest-first eviction in cache.ts with a proper LRU strategy that evicts a configurable batch of entries when at capacity.

Changes

  • LRU trackingget and set now refresh a key's position in the Map (delete + re-insert), so the Map's insertion order always reflects LRU → MRU
  • Batch eviction — when at capacity, evicts ceil(maxEntries * evictBatchFraction) least-recently-used entries at once (default 10%)
  • New config fieldevictBatchFraction added to CacheConfig (default 0.1)
  • Eviction metricsgetStats() now returns evictions count and logs hit rate on every call

Tests

Added test coverage for:

  • LRU ordering after reads and overwrites
  • Batch eviction (50% and 10% fractions)
  • Cache size never exceeds maxEntries under load (200 rapid inserts)
  • Hit rate stays above 80% when recently-set keys are accessed
  • evictions field present in PriceCache.getStats()

Closes #41

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@shaaibu7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

@shaaibu7 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Smartdevs17 Smartdevs17 merged commit 1583d18 into Smartdevs17:main Mar 24, 2026
1 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Oracle cache evicts only one entry at capacity, causing thrashing

2 participants