Remove a specific key from the cache
(&self, key: &K)
| 266 | |
| 267 | /// Remove a specific key from the cache |
| 268 | pub fn remove(&self, key: &K) -> Option<V> { |
| 269 | let mut entries = self.entries.write(); |
| 270 | let mut stats = self.stats.write(); |
| 271 | |
| 272 | if let Some(entry) = entries.remove(key) { |
| 273 | stats.total_entries = entries.len(); |
| 274 | stats.total_size_bytes = stats.total_size_bytes.saturating_sub(entry.size_bytes); |
| 275 | stats.evictions += 1; |
| 276 | |
| 277 | // Unregister memory usage |
| 278 | global_memory_monitor().record_query_deallocation(entry.size_bytes as u64); |
| 279 | |
| 280 | Some(entry.value) |
| 281 | } else { |
| 282 | None |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /// Clear all entries from the cache |
| 287 | pub fn clear(&self) { |