23 lines
387 B
Go
23 lines
387 B
Go
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)
|
|
}
|