固定长度的Map(采用LRU策略)的实现
作者:
zhglance | 来源:发表于
2019-02-14 16:57 被阅读4次import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
public class FixedCapacityMap {
protected static Map<Integer, Long> fixedCapacityCache = Collections.synchronizedMap(new LRUHashMap<>());
public static Long get(int key) {
return fixedCapacityCache.get(key);
}
public static void put(int key, long value) {
fixedCapacityCache.put(key, value);
}
public static int size() {
return fixedCapacityCache.size();
}
static class LRUHashMap<K, V> extends LinkedHashMap<K, V> {
private int capacity = 50;
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > capacity;
}
}
}
本文标题:固定长度的Map(采用LRU策略)的实现
本文链接:https://www.haomeiwen.com/subject/rgzeeqtx.html
网友评论