实现
This commit is contained in:
22
del.go
Normal file
22
del.go
Normal file
@@ -0,0 +1,22 @@
|
||||
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 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if c.cDel != nil {
|
||||
c.cDel(key, *c.data[key])
|
||||
}
|
||||
delete(c.data, key)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Del 删除数据
|
||||
// key: 键 返回值: 是否删除成功 错误
|
||||
func (c *Cache[K, V]) Del(key K) (bool, error) {
|
||||
return c.del(key)
|
||||
}
|
||||
Reference in New Issue
Block a user