1 19 package org.openharmonise.commons.cache; 20 21 import java.util.*; 22 import java.util.logging.*; 23 import java.util.logging.Logger ; 24 25 import org.apache.commons.collections.map.*; 26 27 36 public class LRUCacheMap extends LRUMap { 37 38 39 private boolean m_bIsDependantAware = false; 40 41 44 private static final Logger m_logger = Logger.getLogger(LRUCacheMap.class.getName()); 45 46 49 public LRUCacheMap() { 50 super(100,true); 51 } 52 53 58 public LRUCacheMap(int size) { 59 super(size,true); 60 } 61 62 65 protected boolean removeLRU(AbstractLinkedMap.LinkEntry entry) { 66 67 boolean bRemove = true; 68 69 Object obj = entry.getValue(); 70 71 if(m_logger.isLoggable(Level.FINEST)) { 72 m_logger.logp(Level.FINEST, this.getClass().getName(), "removeLRU", "Removing " + obj); 73 } 74 75 if(obj instanceof CacheableObject) { 76 ((CacheableObject)obj).notifyCacheListeners(); 77 } 78 79 if(m_bIsDependantAware == true 80 && obj instanceof DependableCacheObject 81 && ((DependableCacheObject)obj).hasDependants()) { 82 bRemove = false; 83 } 84 85 return bRemove; 86 } 87 88 89 92 public void clear() { 93 94 for (Iterator iter = keySet().iterator(); iter.hasNext();) { 95 String sKey = (String ) iter.next(); 96 Object obj = get(sKey); 97 98 if(obj instanceof CacheableObject) { 99 ((CacheableObject)obj).notifyCacheListeners(); 100 } 101 } 102 super.clear(); 103 } 104 105 114 public void setDependancyAware(boolean bIsDepAware) { 115 m_bIsDependantAware = bIsDepAware; 116 } 117 118 125 public boolean isDependancyAware() { 126 return m_bIsDependantAware; 127 } 128 } 129 | Popular Tags |