diff --git a/cache/cache.go b/cache/cache.go index f07e545..97da17f 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -22,10 +22,16 @@ func NewSliceCache[T any](fun func() ([]T, error), duration time.Duration) *Slic } } +func (c *SliceCache[T]) FlushCache() { + c.mutex.Lock() + defer c.mutex.Unlock() + c.data = nil +} + func (c *SliceCache[T]) GetCache() []T { l := len(c.data) expired := time.Duration(c.setTime.Unix())+c.expireTime/time.Second < time.Duration(time.Now().Unix()) - if l > 0 && expired || l < 1 { + if l < 1 || (l > 0 && c.expireTime > 0 && expired) { r, err := c.setCacheFunc() if err != nil { log.Printf("set cache err[%s]", err)