Keep variant content types in memory for cache hits (closes #70) #157

Open
clawbot wants to merge 6 commits from issue-70-metacache into next
6 Commits
Author SHA1 Message Date
clawbot 8620a46c90 Test that a failed read during a store keeps the stored content type (closes #70)
check / check (push) Waiting to run
A read that finds a variant in memory but cannot open its file removes
it from memory. When that happens after StoreVariant has added the
variant's content type, a read that opened the variant file before the
store wrote its .meta file finds memory empty and keeps
application/octet-stream there, so every later hit serves the image
with it. The test runs the store, the failed read and the read without
a .meta file in that order, then checks a later hit. It fails now.

Model: opus-5-5
2026-09-29 08:26:48 +00:00
clawbot fa3af3c72e Have Lookup check the disk for variants held in memory too (closes #70)
check / check (push) Successful in 3m36s
Lookup again counts a variant as present only when its file exists.
Treating a variant held in memory as present saved one check of the
disk, but no test covered it, and GetVariant opens the file anyway.

Model: opus-5-5
2026-09-29 07:30:24 +00:00
clawbot 7f358602e4 Keep the content type a store put in memory over one read from disk (closes #70)
check / check (push) Successful in 3m31s
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
2026-09-29 07:29:52 +00:00
clawbot fc87c2117d Test that a read during a store keeps the stored content type (closes #70)
check / check (push) Failing after 4m2s
A GetVariant that begins before StoreVariant finishes can find the
variant file but not yet its .meta file, and so reads
application/octet-stream. When it adds that to memory after the store
added the real type, the wrong type is served to every later hit. The
part of GetVariant that runs after its check of memory moves, unchanged,
into loadVariantWithMeta, so the test can run it after a store. The
test fails now.

Model: opus-5-5
2026-09-29 07:22:21 +00:00
clawbot 1a07e9e261 Keep variant content types in memory for cache hits (closes #70)
Cache.metaCache was declared and never used, so every hit read and
parsed the variant's .meta file. It is now an LRU of up to 10,000
content types (hashicorp/golang-lru/v2), filled by StoreVariant and by
GetVariant after it reads a .meta file. For a variant it holds, Lookup
skips the disk check and GetVariant skips the .meta read; the variant
file is still opened and its size taken from it. Eviction removes the
entry before deleting the files, and GetVariant removes it when the
file will not open, so a missing variant is never served. The cap is a
constant, not a setting. README.md describes it.

Model: opus-5-5
2026-09-29 07:15:11 +00:00
clawbot dd9c85d5ec Test that a cache hit takes the content type from memory (closes #70)
Tests for keeping each variant's content type in memory. A second hit
must still get the stored content type after the variant's .meta file
is deleted, whether the first came from storing the variant or from
reading it after a restart; this fails now. A variant removed by
EvictToLimit, or whose file was deleted from disk, must be a miss and
must not be served, and concurrent stores, reads and evictions run
under the race detector; these pass now and guard the change.

Model: opus-5-5
2026-09-29 07:14:16 +00:00