Insert cached trie data for a block. Evicts the oldest entries when the cache exceeds capacity.
(&self, block_number: u64, data: CachedBlockTrieData)
| 162 | /// |
| 163 | /// Evicts the oldest entries when the cache exceeds capacity. |
| 164 | pub fn insert(&self, block_number: u64, data: CachedBlockTrieData) { |
| 165 | let mut cache = self.cache.lock().expect("SyncTarget lock poisoned"); |
| 166 | cache.insert(block_number, data); |
| 167 | let mut evicted = 0u64; |
| 168 | while cache.len() > CACHE_CAPACITY { |
| 169 | cache.pop_first(); |
| 170 | evicted += 1; |
| 171 | } |
| 172 | if evicted > 0 { |
| 173 | debug!( |
| 174 | target: "base::exex::sync_target", |
| 175 | block_number, |
| 176 | evicted, |
| 177 | "Cache full, evicted oldest entries" |
| 178 | ); |
| 179 | } |
| 180 | debug!( |
| 181 | target: "base::exex::sync_target", |
| 182 | block_number, |
| 183 | cached_blocks = cache.len(), |
| 184 | "Cached trie data for block" |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | /// Take cached trie data for a specific block, removing it from the cache. |
| 189 | pub fn take(&self, block_number: u64) -> Option<CachedBlockTrieData> { |