Delete removes an item from the cache.
(key string)
| 265 | |
| 266 | // Delete removes an item from the cache. |
| 267 | func (c *FileCache) Delete(key string) error { |
| 268 | c.mutex.Lock() |
| 269 | defer c.mutex.Unlock() |
| 270 | |
| 271 | // Remove from in-memory cache and LRU list |
| 272 | if element, exists := c.inMemory[key]; exists { |
| 273 | c.lruList.Remove(element) |
| 274 | delete(c.inMemory, key) |
| 275 | } |
| 276 | |
| 277 | // If persisted, remove the file |
| 278 | if c.persisted { |
| 279 | filePath := filepath.Join(c.dir, key+".json") |
| 280 | if err := os.Remove(filePath); err != nil && !os.IsNotExist(err) { |
| 281 | return fmt.Errorf("failed to remove cache file: %w", err) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | getCacheLogger().Debug("Deleted cache item: %s", key) |
| 286 | |
| 287 | return nil |
| 288 | } |
| 289 | |
| 290 | // Clear removes all items from the cache. |
| 291 | func (c *FileCache) Clear() error { |
nothing calls this directly
no test coverage detected