This commit is contained in:
2025-02-21 08:42:56 +08:00
parent a0ee3b858b
commit 2f99149d92
9 changed files with 146 additions and 124 deletions

16
del.go
View File

@@ -1,17 +1,19 @@
package cache
func (c *Cache[K, V]) del(key K) (bool, error) {
c.mu.Lock()
defer c.mu.Unlock()
if _, ok := c.data[key]; !ok {
dataAny, load := c.data.LoadAndDelete(key)
if !load {
return false, nil
}
if c.cDel != nil {
c.cDel(key, *c.data[key])
data, ok := dataAny.(*Data[V])
if !ok {
return false, TypeErrMsg
}
if c.cDel != nil {
c.cDel(key, *data)
}
delete(c.data, key)
return true, nil
}