From d1fb5605788cce15af820552b3d09d1e848b3650 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 31 Oct 2023 19:23:38 +0800 Subject: [PATCH] fix bug and test set expireTime --- app/cmd/cachemanager/flush_test.go | 16 ++++++++++++++++ app/cmd/reload/reload.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/cmd/cachemanager/flush_test.go b/app/cmd/cachemanager/flush_test.go index 34e89be..d574437 100644 --- a/app/cmd/cachemanager/flush_test.go +++ b/app/cmd/cachemanager/flush_test.go @@ -53,3 +53,19 @@ func TestFlushMapVal(t *testing.T) { 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")) + }) +} diff --git a/app/cmd/reload/reload.go b/app/cmd/reload/reload.go index a610095..e71bd48 100644 --- a/app/cmd/reload/reload.go +++ b/app/cmd/reload/reload.go @@ -261,7 +261,7 @@ func Push(fn func(), a ...any) { func Reload() { anyMap.Flush() - safetyMaps.Flush() + //safetyMaps.Flush() callsM.Flush() flushMapFn.Flush() callll := calls.Load()