From ace163371ab9fc28069cbf55221763c2a65712b1 Mon Sep 17 00:00:00 2001 From: Mathieu Dutour Sikiric Date: Tue, 24 Sep 2024 15:02:42 +0200 Subject: [PATCH] Simplify a little the cache when possible. --- CLI.md | 2 +- linera-views/src/backends/lru_caching.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CLI.md b/CLI.md index 50f865b784bd..6354417c95e2 100644 --- a/CLI.md +++ b/CLI.md @@ -108,7 +108,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp * `--max-stream-queries ` — The maximal number of simultaneous stream queries to the database Default value: `10` -* `--max-cache-size ` — The maximal size of the storage cache +* `--max-cache-size ` — The maximal size of the storage cache, in bytes Default value: `10000000` * `--max-cache-entries ` — The maximal number of entries in the storage cache diff --git a/linera-views/src/backends/lru_caching.rs b/linera-views/src/backends/lru_caching.rs index b3d0d3fcaf34..a9b51879c258 100644 --- a/linera-views/src/backends/lru_caching.rs +++ b/linera-views/src/backends/lru_caching.rs @@ -492,7 +492,6 @@ impl LruPrefixCache { // which is counter productive return; } - let full_prefix = (key_prefix.clone(), CacheEntry::Find); let keys = self .map_find .range(get_interval(key_prefix.clone())) @@ -503,6 +502,19 @@ impl LruPrefixCache { let full_key = (key, CacheEntry::Find); self.remove_from_queue(&full_key); } + if let FindCacheEntry::KeyValues(_) = cache_entry { + let keys = self + .map_value + .range(get_interval(key_prefix.clone())) + .map(|(x,_)| x.clone()) + .collect::>(); + for key in keys { + self.map_value.remove(&key); + let full_key = (key, CacheEntry::Value); + self.remove_from_queue(&full_key); + } + } + let full_prefix = (key_prefix.clone(), CacheEntry::Find); match self.map_find.entry(key_prefix.clone()) { btree_map::Entry::Occupied(mut entry) => { entry.insert(cache_entry);