1 18 package org.apache.activemq.util; 19 20 import java.util.LinkedHashMap ; 21 import java.util.Map ; 22 27 28 public class LRUCache<K, V> extends LinkedHashMap <K, V> { 29 private static final long serialVersionUID=-342098639681884413L; 30 protected int maxCacheSize=10000; 31 32 33 37 public LRUCache(){ 38 super(1000,0.75f,true); 39 } 40 41 53 54 public LRUCache(int initialCapacity,int maximumCacheSize,float loadFactor, boolean accessOrder) { 55 super(initialCapacity,loadFactor,accessOrder); 56 this.maxCacheSize = maximumCacheSize; 57 } 58 59 60 61 64 public int getMaxCacheSize(){ 65 return maxCacheSize; 66 } 67 68 72 public void setMaxCacheSize(int maxCacheSize){ 73 this.maxCacheSize=maxCacheSize; 74 } 75 76 protected boolean removeEldestEntry(Map.Entry entry){ 77 return size() > maxCacheSize; 78 } 79 } 80 | Popular Tags |