From 57d345e4450408ba2fde3761028c3e9cfe04fff8 Mon Sep 17 00:00:00 2001 From: xing Date: Sun, 17 Dec 2023 19:34:04 +0800 Subject: [PATCH] fix var memory cache bug --- cache/vars.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cache/vars.go b/cache/vars.go index 3f42b9f..39ca2d4 100644 --- a/cache/vars.go +++ b/cache/vars.go @@ -156,7 +156,10 @@ type VarMemoryCache[T any] struct { } func (c *VarMemoryCache[T]) ClearExpired(ctx context.Context) { - c.Flush(ctx) + _, ok := c.Get(ctx) + if !ok { + c.Flush(ctx) + } } func NewVarMemoryCache[T any](expireTime func() time.Duration) *VarMemoryCache[T] {