1 3 package jodd.cache; 4 5 import java.util.LinkedHashMap ; 6 import java.util.Iterator ; 7 8 19 public class FIFOCache extends AbstractCacheMap { 20 21 public FIFOCache(int cacheSize) { 22 this(cacheSize, 0); 23 } 24 25 28 public FIFOCache(int cacheSize, long timeout) { 29 this.cacheSize = cacheSize; 30 this.timeout = timeout; 31 cacheMap = new LinkedHashMap (cacheSize + 1, 1.0f, false); 32 } 33 34 35 37 40 public synchronized int prune() { 41 int count = 0; 42 CacheObject first = null; 43 Iterator values = cacheMap.values().iterator(); 44 while (values.hasNext()) { 45 CacheObject co = (CacheObject) values.next(); 46 if (co.isExpired() == true) { 47 values.remove(); 48 count++; 49 } 50 if (first == null) { 51 first = co; 52 } 53 } 54 if (isFull()) { 55 if (first != null) { 56 cacheMap.remove(first.key); 57 } 58 } 59 return count; 60 } 61 } 62 | Popular Tags |