local cache

This commit is contained in:
withchao 2024-01-10 16:13:55 +08:00
parent 2d21ab3aeb
commit 8ff8861603

View File

@ -34,21 +34,20 @@ type cache[V any] struct {
func (c *cache[V]) onEvict(key string, value V) {
lks := c.link.Del(key)
for k := range lks {
if key != k { // prevent deadlock
c.local.Del(k)
}
}
}
func (c *cache[V]) del(key ...string) {
for _, k := range key {
lks := c.link.Del(k)
c.local.Del(k)
//fmt.Println(">>>", lks)
for k := range lks {
c.local.Del(k)
//fmt.Println("+++", k)
}
}
//fmt.Println()
}
func (c *cache[V]) Get(ctx context.Context, key string, fetch func(ctx context.Context) (V, error), opts ...*opt.Option) (V, error) {