Skip to content

fix: evict expired entries from DbCache#302

Open
allamiro wants to merge 1 commit into
lixmal:masterfrom
allamiro:fix/dbcache-eviction
Open

fix: evict expired entries from DbCache#302
allamiro wants to merge 1 commit into
lixmal:masterfrom
allamiro:fix/dbcache-eviction

Conversation

@allamiro

@allamiro allamiro commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #283.

Problem

DbCache checked expiry on retrieval but never removed expired entries (long-standing TODO). With many users, encrypted databases of users who simply walked away accumulated in memory forever.

Change

store() now evicts all expired entries (one retain under the already-held write lock) before inserting. Eviction is opportunistic — any login or expiry refresh cleans the map — which avoids a background task while bounding growth to active users.

Testing

cargo test: 10/10 pass, including a new test that verifies an expired entry is dropped on the next store.


Summary by cubic

Evicts expired entries from DbCache on store to stop unbounded growth from inactive users. Keeps memory bounded without a background task.

  • Bug Fixes
    • Drop all expired entries under the existing write lock before inserting the new value (opportunistic eviction with retain).
    • Add a test verifying an expired entry is removed on the next store.

Written for commit 8dc021a. Summary will update on new commits.

Review in cubic

Expired encrypted databases of inactive users were never removed, so
the in-memory cache grew without bound. store() now drops all expired
entries before inserting (resolves the 'expire old entries' TODO).
@allamiro allamiro force-pushed the fix/dbcache-eviction branch from 8dc021a to 5988fe4 Compare June 13, 2026 00:17
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.

DbCache never evicts expired entries

1 participant