Skip to content
Open
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: 5 additions & 6 deletions fastcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ func (b *bucket) Init(maxBytes uint64) {
}
maxChunks := (maxBytes + chunkSize - 1) / chunkSize
b.chunks = make([][]byte, maxChunks)
b.m = make(map[uint64]uint64)
b.Reset()
}

Expand All @@ -260,11 +259,11 @@ func (b *bucket) Reset() {
b.m = make(map[uint64]uint64)
b.idx = 0
b.gen = 1
atomic.StoreUint64(&b.getCalls, 0)
atomic.StoreUint64(&b.setCalls, 0)
atomic.StoreUint64(&b.misses, 0)
atomic.StoreUint64(&b.collisions, 0)
atomic.StoreUint64(&b.corruptions, 0)
b.getCalls = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.getCalls may cause race conditions if other goroutines read this field concurrently without holding the mutex. If getCalls is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Copilot uses AI. Check for mistakes.
b.setCalls = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.setCalls may cause race conditions if other goroutines read this field concurrently without holding the mutex. If setCalls is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Copilot uses AI. Check for mistakes.
b.misses = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.misses may cause race conditions if other goroutines read this field concurrently without holding the mutex. If misses is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Copilot uses AI. Check for mistakes.
b.collisions = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.collisions may cause race conditions if other goroutines read this field concurrently without holding the mutex. If collisions is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Suggested change
b.collisions = 0
atomic.StoreUint64(&b.collisions, 0)

Copilot uses AI. Check for mistakes.
b.corruptions = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.corruptions may cause race conditions if other goroutines read this field concurrently without holding the mutex. If corruptions is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Suggested change
b.corruptions = 0
atomic.StoreUint64(&b.corruptions, 0)

Copilot uses AI. Check for mistakes.
b.mu.Unlock()
}

Expand Down