gookit/cache

缓存失效的时候,当前进程会挂起,是怎么回事?

lemos1235 opened this issue · 2 comments

我在使用基于内存的那个缓存,发现当缓存失效的时候,当前进程会挂起,怎么回事?

发现过期后进入 Del 函数造成加锁两次,导致当前线程一直被阻塞。

L57 这里吗。 检查代码好像发现这里该用内部的 del() 方法

cache/driver_memory.go

Lines 49 to 61 in 5e0b108

func (c *MemoryCache) get(key string) interface{} {
if item, ok := c.caches[key]; ok {
// check expire time
if item.Exp == 0 || item.Exp > time.Now().Unix() {
return item.Val
}
// has been expired. delete it.
_ = c.Del(key)
}
return nil
}