perf: tighten thumbnail cache memory usage

This commit is contained in:
OpenClaw Agent
2026-09-22 17:39:11 +08:00
parent a2113f831d
commit 9af81fdc8d
2 changed files with 21 additions and 5 deletions
+16
View File
@@ -70,3 +70,19 @@ func TestThumbnailCacheEvictsByBound(t *testing.T) {
t.Fatalf("cache size=%d/list=%d, want 2/2", len(c.items), c.order.Len())
}
}
func TestThumbnailCacheEvictsByBytes(t *testing.T) {
c := newThumbnailCache()
c.maxBytes = 3
for i := 0; i < 2; i++ {
key := thumbnailCacheKey{Path: string(rune('x' + i))}
if _, err := c.Do(key, func() ([]byte, error) { return []byte("xx"), nil }); err != nil {
t.Fatal(err)
}
}
c.mu.Lock()
defer c.mu.Unlock()
if c.bytes > c.maxBytes || len(c.items) != 1 {
t.Fatalf("cache bytes=%d items=%d, want <=%d/1", c.bytes, len(c.items), c.maxBytes)
}
}