Add GetWithoutPromote

This gets the value without promoting it (sort of like a Peak)
This commit is contained in:
Karl Seguin
2022-01-24 12:51:35 +08:00
parent ef4bd54683
commit 451f5a6e42
5 changed files with 45 additions and 0 deletions

View File

@@ -194,6 +194,20 @@ func (_ LayeredCacheTests) PromotedItemsDontGetPruned() {
Expect(cache.Get("11", "a").Value()).To.Equal(11)
}
func (_ LayeredCacheTests) GetWithoutPromoteDoesNotPromote() {
cache := Layered(Configure().ItemsToPrune(10).GetsPerPromote(1))
for i := 0; i < 500; i++ {
cache.Set(strconv.Itoa(i), "a", i, time.Minute)
}
cache.SyncUpdates()
cache.GetWithoutPromote("9", "a")
cache.SyncUpdates()
cache.GC()
Expect(cache.Get("9", "a")).To.Equal(nil)
Expect(cache.Get("10", "a").Value()).To.Equal(10)
Expect(cache.Get("11", "a").Value()).To.Equal(11)
}
func (_ LayeredCacheTests) TrackerDoesNotCleanupHeldInstance() {
cache := Layered(Configure().ItemsToPrune(10).Track())
item0 := cache.TrackingSet("0", "a", 0, time.Minute)