1 17 package org.apache.servicemix.components.cache; 18 19 import java.util.LinkedHashMap ; 20 import java.util.Map ; 21 22 28 public class LRUCache extends LinkedHashMap { 29 private static final long serialVersionUID = -5754338187296859149L; 30 31 protected static final int DEFAULT_INITIAL_CAPACITY = 1000; 32 protected static final float DEFAULT_LOAD_FACTOR = (float) 0.75; 33 34 private int maxSize; 35 36 public LRUCache(int initialCapacity, float loadFactor, boolean accessOrder, int maxSize) { 37 super(initialCapacity, loadFactor, accessOrder); 38 this.maxSize = maxSize; 39 } 40 41 public LRUCache(int maxSize) { 42 this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, true, maxSize); 43 } 44 45 public LRUCache(int maxSize, boolean accessOrder) { 46 this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, accessOrder, maxSize); 47 } 48 49 protected boolean removeEldestEntry(Map.Entry eldest) { 50 return size() > maxSize; 51 } 52 } 53 | Popular Tags |