fix: eth cache memory usage (#16075)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Shane K Moore
2025-05-06 00:38:41 -07:00
committed by GitHub
parent 7d2ac84722
commit 1c7d8a643b

View File

@@ -99,6 +99,14 @@ where
V: InMemorySize,
{
let size = value.size();
if self.cache.limiter().is_over_the_limit(self.cache.len() + 1) {
if let Some((_, evicted)) = self.cache.pop_oldest() {
// update tracked memory with the evicted value
self.memory_usage = self.memory_usage.saturating_sub(evicted.size());
}
}
if self.cache.insert(key, value) {
self.memory_usage = self.memory_usage.saturating_add(size);
true