001 /* 002 @license.text@ 003 */ 004 package biz.hammurapi.cache; 005 006 import java.util.Timer; 007 008 import biz.hammurapi.metrics.MeasurementCategory; 009 010 /** 011 * Cache which supports addition of entries. 012 * @author Pavel Vlasov 013 * @revision $Revision$ 014 */ 015 public class AppendableMemoryCache extends MemoryCache implements AppendableCache { 016 017 public AppendableMemoryCache(AppendableProducer producer, Cache fallBack, MeasurementCategory measurementCategory) { 018 super(producer, fallBack, measurementCategory); 019 } 020 021 public AppendableMemoryCache( 022 AppendableProducer producer, 023 Cache fallBack, 024 MeasurementCategory measurementCategory, 025 Timer timer, long cleanupInterval) { 026 super(producer, fallBack, measurementCategory, timer, cleanupInterval); 027 } 028 029 public Object add(Object value, long time, long expirationTime) { 030 synchronized (cache) { 031 if (reverseCache.containsKey(value)) { 032 return reverseCache.get(value); 033 } 034 } 035 036 Object key=((AppendableProducer) producer).add(value); 037 put(key, value, time, expirationTime); 038 return key; 039 } 040 041 }