From 7f358602e40e50b00b111f683515f20194e62f31 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Tue, 29 Sep 2026 07:29:52 +0000 Subject: [PATCH] Keep the content type a store put in memory over one read from disk (closes #70) GetVariant now adds the content type it read from a .meta file only when memory holds none for the variant, so a type StoreVariant added meanwhile is not replaced. A read that found no .meta file yet still gets application/octet-stream for that one request, as before this change, but no longer leaves it in memory for later hits. Model: opus-5-5 --- TODO.md | 3 ++- internal/imgcache/cache.go | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index c694ba8..8c80174 100644 --- a/TODO.md +++ b/TODO.md @@ -33,7 +33,8 @@ exhaustion - 2026-09-29 variant content types kept in memory (closes #70): `Cache.metaCache` holds the content types of up to 10,000 variants in an LRU (`github.com/hashicorp/golang-lru/v2`), filled by `StoreVariant` and by - `GetVariant` after it reads a `.meta` file; for a variant it holds, `Lookup` + `GetVariant` after it reads a `.meta` file, where a type `StoreVariant` added + meanwhile is kept over the one read; for a variant it holds, `Lookup` skips the check of the disk and `GetVariant` skips the `.meta` read, still opening the variant file and taking the size from it; eviction removes the entry before deleting the files, and `GetVariant` removes it when the file diff --git a/internal/imgcache/cache.go b/internal/imgcache/cache.go index 02a8edd..2390988 100644 --- a/internal/imgcache/cache.go +++ b/internal/imgcache/cache.go @@ -522,7 +522,10 @@ func (c *Cache) IncrementTransformCount(ctx context.Context) { // loadVariantWithMeta is GetVariant for a variant metaCache does not // hold: it reads the content type from the variant's .meta file and -// keeps it in metaCache. +// keeps it in metaCache, unless a StoreVariant has put one there +// meanwhile. The stored one wins, since this read may have found the +// variant file before the store wrote the .meta file, and so got +// application/octet-stream. func (c *Cache) loadVariantWithMeta( cacheKey VariantKey, ) (io.ReadCloser, int64, string, error) { @@ -531,7 +534,7 @@ func (c *Cache) loadVariantWithMeta( return nil, 0, "", err } - c.metaCache.Add(cacheKey, contentType) + c.metaCache.ContainsOrAdd(cacheKey, contentType) return reader, size, contentType, nil }