Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions fastcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type Stats struct {
// MaxBytesSize is the maximum allowed size of the cache in bytes (aka capacity).
MaxBytesSize uint64

// EvictedBytes is the amount of bytes evicted from cache
EvictedBytes uint64

// BigStats contains stats for GetBig/SetBig methods.
BigStats
}
Expand Down Expand Up @@ -234,8 +237,9 @@ type bucket struct {
// idx points to chunks for writing the next (k, v) pair.
idx uint64

collisions uint64
corruptions uint64
collisions uint64
corruptions uint64
evictedBytes uint64
}

func (b *bucket) Init(maxBytes uint64) {
Expand Down Expand Up @@ -266,6 +270,7 @@ func (b *bucket) Reset() {
atomic.StoreUint64(&b.misses, 0)
atomic.StoreUint64(&b.collisions, 0)
atomic.StoreUint64(&b.corruptions, 0)
atomic.StoreUint64(&b.evictedBytes, 0)
b.mu.Unlock()
}

Expand Down Expand Up @@ -303,6 +308,7 @@ func (b *bucket) UpdateStats(s *Stats) {
s.Misses += atomic.LoadUint64(&b.misses)
s.Collisions += atomic.LoadUint64(&b.collisions)
s.Corruptions += atomic.LoadUint64(&b.corruptions)
s.EvictedBytes += atomic.LoadUint64(&b.evictedBytes)

b.mu.RLock()
s.EntriesCount += uint64(len(b.m))
Expand Down Expand Up @@ -371,6 +377,7 @@ func (b *bucket) Set(k, v []byte, h uint64) {
b.idx = idxNew
if needClean {
b.cleanLocked()
atomic.AddUint64(&b.evictedBytes, uint64(len(chunks)*chunkSize))
}
b.mu.Unlock()
}
Expand Down