Skip to content

fix(cache): add LRU eviction and opportunistic expired-key sweep#450

Open
ionfwsrijan wants to merge 1 commit into
utksh1:mainfrom
ionfwsrijan:fix/issue-446-cache-eviction
Open

fix(cache): add LRU eviction and opportunistic expired-key sweep#450
ionfwsrijan wants to merge 1 commit into
utksh1:mainfrom
ionfwsrijan:fix/issue-446-cache-eviction

Conversation

@ionfwsrijan
Copy link
Copy Markdown
Contributor

Description

Adds memory-safety guarantees to the in-memory cache client: a maximum entry cap with LRU eviction, an opportunistic expired-key sweep, and monitoring properties (size, stats) to prevent unbounded memory growth in long-running processes.

Related Issues

Closes #446

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Inserted 10,000+ entries; verified eviction fires once the cap is exceeded
  • Inserted entries with short TTLs; verified the opportunistic sweep removes them after enough writes
  • Called stats and size after evictions and sweeps; confirmed counters incremented
  • Ran existing test suite (if any) — no regressions

Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my own code.
  • My changes generate no new warnings.

- Add max entry cap with LRU eviction when cache exceeds capacity
- Add opportunistic sweep of expired entries every N writes
- Add LRU access tracking to evict least recently used entries first
- Expose size property and stats for monitoring cache health
- Prevent unbounded memory growth in long-running processes
@ionfwsrijan
Copy link
Copy Markdown
Contributor Author

@utksh1 You may review and merge

@utksh1 utksh1 added level:intermediate 35 pts difficulty label for moderate contributor PRs type:performance Performance work category bonus label type:bug Bug fix work category bonus label area:backend Backend API, database, or service work labels May 31, 2026
Copy link
Copy Markdown
Owner

@utksh1 utksh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tightening the in-memory cache. Please add focused unit coverage before merge: LRU eviction order, expiry cleanup removing access-order entries, delete_prefix cleanup, and edge cases such as max_entries <= 0. Cache eviction changes are easy to regress and this PR currently has no tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work level:intermediate 35 pts difficulty label for moderate contributor PRs type:bug Bug fix work category bonus label type:performance Performance work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-memory CacheClient never purges expired keys proactively (unbounded growth in long-running processes)

2 participants