Skip to content

Commit

Permalink
fix estimated size
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiling-J committed Oct 28, 2024
1 parent 4cfffb7 commit d40c55f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestCache_EstimatedSize(t *testing.T) {
})
wg.Go(func() error {
defer cfn()
for i := 0; i < 1000000; i++ {
for i := 0; i < 1200; i++ {
if i%2 == 0 {
client.Set(i, 1, 1)
} else {
Expand All @@ -256,6 +256,8 @@ func TestCache_EstimatedSize(t *testing.T) {
return nil
})
require.Nil(t, wg.Wait())
client.Wait()
require.Equal(t, 500, client.EstimatedSize())
}

func TestCache_Doorkeeper(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (s *Store[K, V]) Len() int {

func (s *Store[K, V]) EstimatedSize() int {
s.policyMu.Lock()
total := s.policy.slru.protected.Len() + s.policy.slru.probation.Len()
total := s.policy.window.Len() + s.policy.slru.protected.Len() + s.policy.slru.probation.Len()
s.policyMu.Unlock()
return total
}
Expand Down

0 comments on commit d40c55f

Please sign in to comment.