diff --git a/fastcache.go b/fastcache.go index 20a3c02..342b67d 100644 --- a/fastcache.go +++ b/fastcache.go @@ -53,6 +53,9 @@ type Stats struct { // BytesSize is the current size of the cache in bytes. BytesSize uint64 + // MaxBytesSize is the maximum allowed size of the cache in bytes (aka capacity). + MaxBytesSize uint64 + // BigStats contains stats for GetBig/SetBig methods. BigStats } @@ -296,6 +299,7 @@ func (b *bucket) UpdateStats(s *Stats) { for _, chunk := range b.chunks { s.BytesSize += uint64(cap(chunk)) } + s.MaxBytesSize += uint64(len(b.chunks))*chunkSize b.mu.RUnlock() } diff --git a/fastcache_test.go b/fastcache_test.go index 7e579dd..6ad39f0 100644 --- a/fastcache_test.go +++ b/fastcache_test.go @@ -112,7 +112,10 @@ func TestCacheWrap(t *testing.T) { t.Fatalf("unexpected number of items; got %d; cannot be smaller than %d", s.EntriesCount, calls/5) } if s.BytesSize < 1024 { - t.Fatalf("unexpected number of bytesSize; got %d; cannot be smaller than %d", s.BytesSize, 1024) + t.Fatalf("unexpected BytesSize; got %d; cannot be smaller than %d", s.BytesSize, 1024) + } + if s.MaxBytesSize < 32*1024*1024 { + t.Fatalf("unexpected MaxBytesSize; got %d; cannot be smaller than %d", s.MaxBytesSize, 32*1024*1024) } }