Conditionally prune more than itemsToPrune items
It's possible, though unlikely, that c.size will be larger than c.maxSize by more than c.itemsToPrune. The most likely case that this can happen is when using SetMaxSize to dynamically adjust the cache size. The gc will now always clear to at least c.maxSize.
This commit is contained in:
@@ -18,6 +18,7 @@ func Test_Cache(t *testing.T) {
|
||||
|
||||
func (_ CacheTests) DeletesAValue() {
|
||||
cache := New(Configure())
|
||||
defer cache.Stop()
|
||||
Expect(cache.ItemCount()).To.Equal(0)
|
||||
|
||||
cache.Set("spice", "flow", time.Minute)
|
||||
@@ -32,6 +33,7 @@ func (_ CacheTests) DeletesAValue() {
|
||||
|
||||
func (_ CacheTests) DeletesAPrefix() {
|
||||
cache := New(Configure())
|
||||
defer cache.Stop()
|
||||
Expect(cache.ItemCount()).To.Equal(0)
|
||||
|
||||
cache.Set("aaa", "1", time.Minute)
|
||||
@@ -55,6 +57,7 @@ func (_ CacheTests) DeletesAPrefix() {
|
||||
|
||||
func (_ CacheTests) DeletesAFunc() {
|
||||
cache := New(Configure())
|
||||
defer cache.Stop()
|
||||
Expect(cache.ItemCount()).To.Equal(0)
|
||||
|
||||
cache.Set("a", 1, time.Minute)
|
||||
|
Reference in New Issue
Block a user