Skip to content

feat: in-memory LRU email body cache#1280

Closed
mavonx wants to merge 1 commit into
floatpane:masterfrom
mavonx:fix/issue-1171
Closed

feat: in-memory LRU email body cache#1280
mavonx wants to merge 1 commit into
floatpane:masterfrom
mavonx:fix/issue-1171

Conversation

@mavonx
Copy link
Copy Markdown
Contributor

@mavonx mavonx commented May 12, 2026

What?

Replaces the disk-only email body cache with an in-memory LRU cache backed by write-through disk persistence.

  • Single global LRU instance shared across all folders via sync.Once singleton.
  • Fast Get() and Put() operations — O(1) via hashmap + doubly-linked list.
  • Write-through: every Get() and Put() immediately persists to disk, so no data is lost on crash.
  • Eviction removes least-recently-used entries from both memory and disk atomically.
  • On the first GetLRUInstance() call, LoadFromDisk() restores LRU order using LastAccessedAt timestamps sorted oldest-first, so the most recently accessed email ends up at the front.

Why?

The previous disk-only approach had two bottlenecks: GetCachedEmailBody() read the entire folder JSON file on every call, and pruneEmailBodyCacheSize() loaded all folder files on every SaveEmailBody() call. With multiple accounts and many folders, this becomes expensive.

Related #1171

@mavonx mavonx requested a review from a team as a code owner May 12, 2026 22:17
@floatpanebot floatpanebot added enhancement New feature or request area/config Configuration / settings size/XL Diff: 800+ lines and removed enhancement New feature or request labels May 12, 2026
@floatpanebot
Copy link
Copy Markdown
Member

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@mavonx mavonx closed this May 12, 2026
@mavonx mavonx deleted the fix/issue-1171 branch May 12, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Configuration / settings size/XL Diff: 800+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants