Keep posters and casts between runs

Posters (the downloaded bytes, per size, 30 days, at most 200 MB) and
casts (people.json, 7 days, at most 2000) are stored in the user's cache
directory (os.UserCacheDir()/arr-tui) and used on the next start before
asking the servers. Expired posters are pruned at startup, casts are
written shortly after new ones arrive and on exit. Tests turn the cache
off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 10:35:02 +02:00
co-authored by Claude Opus 5.5
parent 4eace6849e
commit 1056846a48
10 changed files with 381 additions and 13 deletions
+17 -3
View File
@@ -525,9 +525,23 @@ func (a *App) loadCover(ref coverRef, done func(*image.RGBA, error)) {
ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
defer cancel()
var img *image.RGBA
data, err := ref.fetch(ctx, large)
if err == nil {
img, err = decodeCover(data, maxHeight)
var err error
// A copy from an earlier run is used while it is fresh enough.
if data, ok := a.disk.readPoster(ref.key, large); ok {
if img, err = decodeCover(data, maxHeight); err != nil {
a.disk.dropPoster(ref.key, large)
img = nil
}
}
if img == nil {
var data []byte
data, err = ref.fetch(ctx, large)
if err == nil {
img, err = decodeCover(data, maxHeight)
}
if err == nil {
a.disk.writePoster(ref.key, large, data)
}
}
a.post(func() {
waiters := c.waiting[ref.key]