fix bug and test set expireTime

This commit is contained in:
xing 2023-10-31 19:23:38 +08:00
parent 42484e3f96
commit d1fb560578
2 changed files with 17 additions and 1 deletions

View File

@ -53,3 +53,19 @@ func TestFlushMapVal(t *testing.T) {
fmt.Println(vv.Get(ctx, 6)) fmt.Println(vv.Get(ctx, 6))
}) })
} }
func TestSetExpireTime(t *testing.T) {
t.Run("t1", func(t *testing.T) {
c := NewMemoryMapCache[string, string](nil, nil, time.Second, "xx")
c.Set(ctx, "xx", "yy")
fmt.Println(c.Get(ctx, "xx"))
time.Sleep(time.Second)
fmt.Println(c.Get(ctx, "xx"))
SetExpireTime(3*time.Second, "xx")
c.Set(ctx, "xx", "yyy")
time.Sleep(time.Second)
fmt.Println(c.Get(ctx, "xx"))
time.Sleep(3 * time.Second)
fmt.Println(c.Get(ctx, "xx"))
})
}

View File

@ -261,7 +261,7 @@ func Push(fn func(), a ...any) {
func Reload() { func Reload() {
anyMap.Flush() anyMap.Flush()
safetyMaps.Flush() //safetyMaps.Flush()
callsM.Flush() callsM.Flush()
flushMapFn.Flush() flushMapFn.Flush()
callll := calls.Load() callll := calls.Load()