/** * Retrieve an entry from the cache. * * <p>This LRU cache supports timeouts, so if the cached object has expired then we return null, * just as if the entry wasn't found. */ @Override public synchronized Object get(String key) { Object value = null; ExpiringCacheEntry entry = null; synchronized (this) { entry = (ExpiringCacheEntry) super.get(key); } if (entry != null) { value = entry.getValue(); // if the value is null then that means this entry expired if (value == null) { log.debug("EXPIRED [" + key + "]"); hits--; super.remove(key); } } return value; }
/** * Store an entry in the cache. * * <p>We wrap the cached object in our ExpiringCacheEntry object so that we can track when the * entry has expired. */ @Override public synchronized void put(String key, Object value) { ExpiringCacheEntry entry = new ExpiringCacheEntry(value, this.timeout); super.put(key, entry); }