Skip to content

Commit fbc4902

Browse files
authored
Reset full is false when pop from bytes queue (#223)
Related to issue #214
1 parent ccdbc60 commit fbc4902

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

bigcache_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,33 @@ func TestCacheCapacity(t *testing.T) {
490490
assertEqual(t, 40960, cache.Capacity())
491491
}
492492

493+
func TestRemoveEntriesWhenShardIsFull(t *testing.T) {
494+
t.Parallel()
495+
496+
// given
497+
cache, _ := NewBigCache(Config{
498+
Shards: 1,
499+
LifeWindow: 100 * time.Second,
500+
MaxEntriesInWindow: 100,
501+
MaxEntrySize: 256,
502+
HardMaxCacheSize: 1,
503+
})
504+
505+
value := blob('a', 1024*300)
506+
507+
// when
508+
cache.Set("key", value)
509+
cache.Set("key", value)
510+
cache.Set("key", value)
511+
cache.Set("key", value)
512+
cache.Set("key", value)
513+
cachedValue, err := cache.Get("key")
514+
515+
// then
516+
noError(t, err)
517+
assertEqual(t, value, cachedValue)
518+
}
519+
493520
func TestCacheStats(t *testing.T) {
494521
t.Parallel()
495522

queue/bytes_queue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ func (q *BytesQueue) Pop() ([]byte, error) {
173173
q.rightMargin = q.tail
174174
}
175175

176+
q.full = false
177+
176178
return data, nil
177179
}
178180

0 commit comments

Comments
 (0)