Delete 删除缓存
(key string)
| 209 | |
| 210 | // Delete 删除缓存 |
| 211 | func (c *DiskCache) Delete(key string) error { |
| 212 | c.mutex.Lock() |
| 213 | defer c.mutex.Unlock() |
| 214 | |
| 215 | meta, exists := c.metadata[key] |
| 216 | if !exists { |
| 217 | return nil |
| 218 | } |
| 219 | |
| 220 | // 删除文件 |
| 221 | filename := c.getFilename(key) |
| 222 | os.Remove(filepath.Join(c.path, filename)) |
| 223 | os.Remove(filepath.Join(c.path, filename+".meta")) |
| 224 | |
| 225 | // 更新元数据 |
| 226 | c.currSize -= int64(meta.Size) |
| 227 | delete(c.metadata, key) |
| 228 | |
| 229 | return nil |
| 230 | } |
| 231 | |
| 232 | // Has 检查缓存是否存在 |
| 233 | func (c *DiskCache) Has(key string) bool { |
no test coverage detected