diff --git a/bigcache_test.go b/bigcache_test.go index 4bf28a5d..a28cc9fe 100644 --- a/bigcache_test.go +++ b/bigcache_test.go @@ -490,6 +490,33 @@ func TestCacheCapacity(t *testing.T) { assertEqual(t, 40960, cache.Capacity()) } +func TestRemoveEntriesWhenShardIsFull(t *testing.T) { + t.Parallel() + + // given + cache, _ := NewBigCache(Config{ + Shards: 1, + LifeWindow: 100 * time.Second, + MaxEntriesInWindow: 100, + MaxEntrySize: 256, + HardMaxCacheSize: 1, + }) + + value := blob('a', 1024*300) + + // when + cache.Set("key", value) + cache.Set("key", value) + cache.Set("key", value) + cache.Set("key", value) + cache.Set("key", value) + cachedValue, err := cache.Get("key") + + // then + noError(t, err) + assertEqual(t, value, cachedValue) +} + func TestCacheStats(t *testing.T) { t.Parallel() diff --git a/queue/bytes_queue.go b/queue/bytes_queue.go index b45387b9..0984980d 100644 --- a/queue/bytes_queue.go +++ b/queue/bytes_queue.go @@ -173,6 +173,8 @@ func (q *BytesQueue) Pop() ([]byte, error) { q.rightMargin = q.tail } + q.full = false + return data, nil }