Skip to content

feat: in-memory LRU email body cache#1281

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

feat: in-memory LRU email body cache#1281
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:50
@floatpanebot floatpanebot added area/config Configuration / settings enhancement New feature or request size/L Diff: 201–800 lines labels May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Configuration / settings enhancement New feature or request size/L Diff: 201–800 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants