perf: tighten thumbnail cache memory usage
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user