evictLRU removes the least recently used item from the cache. Must be called with mutex held.
()
| 243 | // evictLRU removes the least recently used item from the cache. |
| 244 | // Must be called with mutex held. |
| 245 | func (c *FileCache) evictLRU() { |
| 246 | element := c.lruList.Back() |
| 247 | if element == nil { |
| 248 | return |
| 249 | } |
| 250 | |
| 251 | entry := element.Value.(*lruEntry) |
| 252 | c.lruList.Remove(element) |
| 253 | delete(c.inMemory, entry.key) |
| 254 | |
| 255 | getCacheLogger().Debug("Evicted LRU item: %s (cache size limit: %d)", entry.key, c.maxSize) |
| 256 | |
| 257 | // If persisted, remove the file |
| 258 | if c.persisted { |
| 259 | filePath := filepath.Join(c.dir, entry.key+".json") |
| 260 | if err := os.Remove(filePath); err != nil && !os.IsNotExist(err) { |
| 261 | getCacheLogger().Debug("Failed to remove evicted cache file: %v", err) |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // Delete removes an item from the cache. |
| 267 | func (c *FileCache) Delete(key string) error { |
no test coverage detected