cache disk blocks in an LRU cache

Improves read access by factor 4 for small trees.
This commit is contained in:
2018-11-24 15:07:37 +01:00
parent 9889252205
commit d67e452a91
7 changed files with 146 additions and 19 deletions

View File

@@ -0,0 +1,35 @@
package org.lucares.utils.cache;
import java.util.LinkedHashMap;
import java.util.Map;
public class LRUCache<K, V> {
private final LinkedHashMap<K, V> cache;
public LRUCache(final int maxEntries) {
this.cache = new LinkedHashMap<>(16, 0.75f, true) {
private static final long serialVersionUID = 1L;
protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return size() > maxEntries;
}
};
}
public V put(final K key, final V value) {
return cache.put(key, value);
}
public V get(final K key) {
return cache.get(key);
}
public V remove(final K key) {
return cache.remove(key);
}
public int size() {
return cache.size();
}
}