Skip to content

feat(config): add LRU eviction#1227

Merged
andrinoff merged 4 commits intofloatpane:masterfrom
mavonx:fix/issue-1171
May 5, 2026
Merged

feat(config): add LRU eviction#1227
andrinoff merged 4 commits intofloatpane:masterfrom
mavonx:fix/issue-1171

Conversation

@mavonx
Copy link
Copy Markdown
Contributor

@mavonx mavonx commented May 3, 2026

What?

Implemented a size-based LRU (Least Recently Used) eviction policy for the email body cache.

Why?

The cache grows without bound, reaching hundreds of MB or GB after heavy use. This causes disk quota issues on devices with small storage.

Closes #1171

@mavonx mavonx requested a review from a team as a code owner May 3, 2026 20:53
@floatpanebot floatpanebot added the enhancement New feature or request label May 3, 2026
Copy link
Copy Markdown
Member

@floatpanebot floatpanebot left a comment

Choose a reason for hiding this comment

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

Hi @Haroka-74! Please fix the following issues with your PR:

  • Title: Is too long (50 characters). The PR title must be strictly under 40 characters.

@floatpanebot floatpanebot added the area/config Configuration / settings label May 3, 2026
Copy link
Copy Markdown
Member

@floatpanebot floatpanebot left a comment

Choose a reason for hiding this comment

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

Hi @Haroka-74! Please fix the following issues with your PR:

  • Title: Is too long (50 characters). The PR title must be strictly under 40 characters.

@mavonx mavonx changed the title feat(config): add LRU eviction to email body cache feat(config): add LRU eviction May 3, 2026
@floatpanebot floatpanebot dismissed stale reviews from themself May 3, 2026 20:54

Formatting issues have been resolved. Thank you!

@andrinoff
Copy link
Copy Markdown
Member

@Haroka-74 threshold should be configurable in the config. Let the default remain 500mb. but add it in config. Also, if you can, edit the public docs to say how to configure it and what the key in config.json does.

@mavonx
Copy link
Copy Markdown
Contributor Author

mavonx commented May 4, 2026

@andrinoff

Sounds good, I’ll sort it out tonight.
Does the current implementation look good, or anything else I should tweak?

@andrinoff
Copy link
Copy Markdown
Member

@andrinoff

Sounds good, I’ll sort it out tonight. Does the current implementation look good, or anything else I should tweak?

i'll check the PR later, quite busy today.

@floatpanebot floatpanebot added the area/docs Docs site / README label May 4, 2026
@mavonx
Copy link
Copy Markdown
Contributor Author

mavonx commented May 4, 2026

@andrinoff Done.

Comment thread config/cache.go Outdated

body.CachedAt = time.Now()
body.LastAccessedAt = time.Now()
body.SizeBytes = len(body.Body)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this does not count CachedAttachments, while it should. Will lead to a much larger cache, than set in config.

Comment thread config/cache.go Outdated
Comment on lines 548 to 552
if calculateTotalCacheSize(cache)+body.SizeBytes > threshold {
evict(cache, body.SizeBytes, threshold)
}

cache.Bodies = append(cache.Bodies, body)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If one new email is more than the threshold, evict will drain the cache and still append.

Comment thread config/cache.go
Body string `json:"body"`
Attachments []CachedAttachment `json:"attachments,omitempty"`
CachedAt time.Time `json:"cached_at"`
LastAccessedAt time.Time `json:"last_accessed_at"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As far as I see, this is never updated. Should be updated on GetCachedEmailBody.

Comment thread config/cache.go
@@ -522,6 +544,11 @@ func SaveEmailBody(folderName string, body CachedEmailBody) error {
}
}
if !found {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The least of my concerns, but also worth noting, that, if the email is changed (found=true still) the cache is not going to be evicted

@mavonx mavonx requested a review from andrinoff May 4, 2026 21:07
@andrinoff
Copy link
Copy Markdown
Member

/approve

Copy link
Copy Markdown
Member

@floatpanebot floatpanebot left a comment

Choose a reason for hiding this comment

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

Approved on behalf of @andrinoff via /approve command.

@andrinoff andrinoff merged commit cd409ca into floatpane:master May 5, 2026
13 checks passed
@mavonx mavonx deleted the fix/issue-1171 branch May 5, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Configuration / settings area/docs Docs site / README enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Body cache has no max size or LRU eviction

3 participants