1 18 19 package org.apache.roller.util.cache; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 25 28 public class ExpiringLRUCacheImpl extends LRUCacheImpl { 29 30 private static Log log = LogFactory.getLog(ExpiringLRUCacheImpl.class); 31 32 private long timeout = 0; 33 34 35 protected ExpiringLRUCacheImpl(String id) { 36 37 super(id); 38 this.timeout = 60 * 60 * 1000; 39 } 40 41 42 protected ExpiringLRUCacheImpl(String id, int maxsize, long timeout) { 43 44 super(id, maxsize); 45 46 if(timeout > 0) { 48 this.timeout = timeout * 1000; 49 } 50 } 51 52 53 59 public synchronized void put(String key, Object value) { 60 61 ExpiringCacheEntry entry = new ExpiringCacheEntry(value, this.timeout); 62 super.put(key, entry); 63 } 64 65 66 72 public Object get(String key) { 73 74 Object value = null; 75 ExpiringCacheEntry entry = null; 76 77 synchronized(this) { 78 entry = (ExpiringCacheEntry) super.get(key); 79 } 80 81 if (entry != null) { 82 83 value = entry.getValue(); 84 85 if (value == null) { 87 log.debug("EXPIRED ["+key+"]"); 88 hits--; 89 super.remove(key); 90 } 91 } 92 93 return value; 94 } 95 96 } 97 | Popular Tags |