This commit is contained in:
2024-08-17 12:04:33 +08:00
commit c13f9b8b82
12 changed files with 791 additions and 0 deletions

22
del.go Normal file
View 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)
}