Trim LRU maps after dropping entries

This commit is contained in:
embeddedt 2024-09-21 14:21:18 -04:00
parent d8e937720f
commit dee2627df9
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -28,6 +28,7 @@ public class LRUMap<K, V> extends Object2ObjectLinkedOpenHashMap<K, V> {
} }
public void dropEntriesToMeetSize(int size) { public void dropEntriesToMeetSize(int size) {
int expectedQuota = size;
// Increase allowed size quota to include permanent entries // Increase allowed size quota to include permanent entries
size += permanentEntries.size(); size += permanentEntries.size();
int prevSize = size(); int prevSize = size();
@ -39,6 +40,7 @@ public class LRUMap<K, V> extends Object2ObjectLinkedOpenHashMap<K, V> {
iterator.remove(); iterator.remove();
} }
} }
trim(size() + expectedQuota);
if(ModernFixPlatformHooks.INSTANCE.isDevEnv()) { if(ModernFixPlatformHooks.INSTANCE.isDevEnv()) {
ModernFix.LOGGER.warn("Trimmed map from {} to {} entries", prevSize, size); ModernFix.LOGGER.warn("Trimmed map from {} to {} entries", prevSize, size);
} }