up
This commit is contained in:
16
del.go
16
del.go
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user