Evict all cache entries belonging to a single `(database_id, tenant_id, collection)`.
(&mut self, database_id: u64, tenant_id: u64, collection: &str)
| 259 | |
| 260 | /// Evict all cache entries belonging to a single `(database_id, tenant_id, collection)`. |
| 261 | pub fn evict_collection(&mut self, database_id: u64, tenant_id: u64, collection: &str) { |
| 262 | let shard = match self.shards.get_mut(&database_id) { |
| 263 | Some(s) => s, |
| 264 | None => return, |
| 265 | }; |
| 266 | let before = shard.entries.len(); |
| 267 | shard |
| 268 | .entries |
| 269 | .retain(|k, _| !(k.tenant_id == tenant_id && k.collection == collection)); |
| 270 | let after = shard.entries.len(); |
| 271 | let removed = before.saturating_sub(after); |
| 272 | shard |
| 273 | .order |
| 274 | .retain(|k| !(k.tenant_id == tenant_id && k.collection == collection)); |
| 275 | if removed > 0 { |
| 276 | if let Some(count) = shard.tenant_counts.get_mut(&tenant_id) { |
| 277 | *count = count.saturating_sub(removed); |
| 278 | } |
| 279 | self.total = self.total.saturating_sub(removed); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /// Evict all cache entries belonging to a specific tenant within a database. |
| 284 | pub fn evict_tenant(&mut self, database_id: u64, tenant_id: u64) { |