Class ConcurrentFIFOExoCache<K extends Serializable,V>
- java.lang.Object
-
- org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache<K,V>
-
- All Implemented Interfaces:
ExoCache<K,V>
- Direct Known Subclasses:
AsyncInvalidationExoCache,FIFOExoCache,SimpleExoCache,SimpleReplicatedExoCache
public class ConcurrentFIFOExoCache<K extends Serializable,V> extends Object implements ExoCache<K,V>
AnExoCacheimplementation based onConcurrentHashMapthat minimize locking. Cache entries are maintained in a fifo list that is used for the fifo eviction policy.- Version:
- $Revision$
- Author:
- Julien Viet
-
-
Constructor Summary
Constructors Constructor Description ConcurrentFIFOExoCache()ConcurrentFIFOExoCache(int maxSize)ConcurrentFIFOExoCache(int maxSize, org.exoplatform.services.log.Log log)ConcurrentFIFOExoCache(String name, int maxSize)ConcurrentFIFOExoCache(String name, int maxSize, org.exoplatform.services.log.Log log)ConcurrentFIFOExoCache(org.exoplatform.services.log.Log log)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCacheListener(CacheListener<? super K,? super V> listener)Add a listener.voidassertConsistent()voidclearCache()Clears the cache.Vget(Serializable name)Performs a lookup operation.List<? extends V>getCachedObjects()Returns a list of cached object that are considered as valid when the method is called.intgetCacheHit()Returns the number of time the cache was queried and a valid entry was returned.intgetCacheMiss()Returns the number of time the cache was queried and no entry was returned.intgetCacheSize()Returns the number of entries in the cache.StringgetLabel()Returns the cache labelList<ListenerContext<K,V>>getListeners()longgetLiveTime()Returns the maximum life time of an entry in the cache.longgetLiveTimeMillis()intgetMaxSize()Returns the maximum capacity of the cache.StringgetName()Returns the cache namebooleanisLogEnabled()voidonClearCache()on clear cache eventvoidonExpire(K key, V obj)On expire entry eventvoidonGet(K key, V obj)On get entry eventvoidonPut(K key, V obj)On put entry eventvoidonPutLocal(K key, V obj)On put entry eventvoidonRemove(K key, V obj)On remove entry eventvoidput(K name, V obj)Performs a put in the cache.voidputLocal(K name, V obj)Performs a put in the cache local mode (avoid replication).voidputMap(Map<? extends K,? extends V> objs)Performs a put of all the entries provided by the map argument.Vremove(Serializable name)Removes an entry from the cache.List<? extends V>removeCachedObjects()Clears the cache and returns the list of cached object that are considered as valid when the method is called.voidselect(CachedObjectSelector<? super K,? super V> selector)Selects a subset of the cache.voidsetLabel(String name)Sets the cache labelvoidsetLiveTime(long period)Sets the maximum life time of an entry in the cache.voidsetLiveTimeMillis(long liveTimeMillis)voidsetLogEnabled(boolean logEnabled)voidsetMaxSize(int max)Sets the maximum capacity of the cache.voidsetName(String s)Sets the cache name.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.exoplatform.services.cache.ExoCache
putAsyncMap, removeLocal
-
-
-
-
Constructor Detail
-
ConcurrentFIFOExoCache
public ConcurrentFIFOExoCache()
-
ConcurrentFIFOExoCache
public ConcurrentFIFOExoCache(org.exoplatform.services.log.Log log)
-
ConcurrentFIFOExoCache
public ConcurrentFIFOExoCache(int maxSize)
-
ConcurrentFIFOExoCache
public ConcurrentFIFOExoCache(int maxSize, org.exoplatform.services.log.Log log)
-
ConcurrentFIFOExoCache
public ConcurrentFIFOExoCache(String name, int maxSize)
-
ConcurrentFIFOExoCache
public ConcurrentFIFOExoCache(String name, int maxSize, org.exoplatform.services.log.Log log)
-
-
Method Detail
-
assertConsistent
public void assertConsistent()
-
getName
public String getName()
Description copied from interface:ExoCacheReturns the cache name- Specified by:
getNamein interfaceExoCache<K extends Serializable,V>- Returns:
- the cache name
-
setName
public void setName(String s)
Description copied from interface:ExoCacheSets the cache name.- Specified by:
setNamein interfaceExoCache<K extends Serializable,V>- Parameters:
s- the cache name
-
getLabel
public String getLabel()
Description copied from interface:ExoCacheReturns the cache label- Specified by:
getLabelin interfaceExoCache<K extends Serializable,V>- Returns:
- the cache label
-
setLabel
public void setLabel(String name)
Description copied from interface:ExoCacheSets the cache label- Specified by:
setLabelin interfaceExoCache<K extends Serializable,V>- Parameters:
name- the cache label
-
getLiveTime
public long getLiveTime()
Description copied from interface:ExoCacheReturns the maximum life time of an entry in the cache. The life time is a value in seconds, a negative value means that the life time is infinite.- Specified by:
getLiveTimein interfaceExoCache<K extends Serializable,V>- Returns:
- the live time
-
setLiveTime
public void setLiveTime(long period)
Description copied from interface:ExoCacheSets the maximum life time of an entry in the cache.- Specified by:
setLiveTimein interfaceExoCache<K extends Serializable,V>- Parameters:
period- the live time
-
getLiveTimeMillis
public long getLiveTimeMillis()
-
setLiveTimeMillis
public void setLiveTimeMillis(long liveTimeMillis)
-
getMaxSize
public int getMaxSize()
Description copied from interface:ExoCacheReturns the maximum capacity of the cache.- Specified by:
getMaxSizein interfaceExoCache<K extends Serializable,V>- Returns:
- the maximum capacity
-
setMaxSize
public void setMaxSize(int max)
Description copied from interface:ExoCacheSets the maximum capacity of the cache.- Specified by:
setMaxSizein interfaceExoCache<K extends Serializable,V>- Parameters:
max- the maximum capacity
-
get
public V get(Serializable name)
Description copied from interface:ExoCachePerforms a lookup operation.- Specified by:
getin interfaceExoCache<K extends Serializable,V>- Parameters:
name- the cache key- Returns:
- the cached value which may be evaluated to null
-
put
public void put(K name, V obj)
Description copied from interface:ExoCachePerforms a put in the cache.- Specified by:
putin interfaceExoCache<K extends Serializable,V>- Parameters:
name- the cache keyobj- the cached value
-
putLocal
public void putLocal(K name, V obj)
Description copied from interface:ExoCachePerforms a put in the cache local mode (avoid replication).- Specified by:
putLocalin interfaceExoCache<K extends Serializable,V>- Parameters:
name- the cache keyobj- the cached value
-
putMap
public void putMap(Map<? extends K,? extends V> objs)
Description copied from interface:ExoCachePerforms a put of all the entries provided by the map argument.- Specified by:
putMapin interfaceExoCache<K extends Serializable,V>- Parameters:
objs- the objects to put
-
remove
public V remove(Serializable name)
Description copied from interface:ExoCacheRemoves an entry from the cache.- Specified by:
removein interfaceExoCache<K extends Serializable,V>- Parameters:
name- the cache key- Returns:
- the previously cached value or null if no entry existed or that entry value was evaluated to null
-
getCachedObjects
public List<? extends V> getCachedObjects()
Description copied from interface:ExoCacheReturns a list of cached object that are considered as valid when the method is called. Any non valid object will not be returned.- Specified by:
getCachedObjectsin interfaceExoCache<K extends Serializable,V>- Returns:
- the list of cached objects
-
removeCachedObjects
public List<? extends V> removeCachedObjects()
Description copied from interface:ExoCacheClears the cache and returns the list of cached object that are considered as valid when the method is called. Any non valid object will not be returned.- Specified by:
removeCachedObjectsin interfaceExoCache<K extends Serializable,V>- Returns:
- the list of cached objects
-
clearCache
public void clearCache()
Description copied from interface:ExoCacheClears the cache.- Specified by:
clearCachein interfaceExoCache<K extends Serializable,V>
-
select
public void select(CachedObjectSelector<? super K,? super V> selector) throws Exception
Description copied from interface:ExoCacheSelects a subset of the cache.
-
getCacheSize
public int getCacheSize()
Description copied from interface:ExoCacheReturns the number of entries in the cache.- Specified by:
getCacheSizein interfaceExoCache<K extends Serializable,V>- Returns:
- the size of the cache
-
getCacheHit
public int getCacheHit()
Description copied from interface:ExoCacheReturns the number of time the cache was queried and a valid entry was returned.- Specified by:
getCacheHitin interfaceExoCache<K extends Serializable,V>- Returns:
- the cache hits
-
getCacheMiss
public int getCacheMiss()
Description copied from interface:ExoCacheReturns the number of time the cache was queried and no entry was returned.- Specified by:
getCacheMissin interfaceExoCache<K extends Serializable,V>- Returns:
- the cache misses
-
addCacheListener
public void addCacheListener(CacheListener<? super K,? super V> listener)
Description copied from interface:ExoCacheAdd a listener.- Specified by:
addCacheListenerin interfaceExoCache<K extends Serializable,V>- Parameters:
listener- the listener to add
-
isLogEnabled
public boolean isLogEnabled()
- Specified by:
isLogEnabledin interfaceExoCache<K extends Serializable,V>
-
setLogEnabled
public void setLogEnabled(boolean logEnabled)
- Specified by:
setLogEnabledin interfaceExoCache<K extends Serializable,V>
-
onExpire
public void onExpire(K key, V obj)
Description copied from interface:ExoCacheOn expire entry event- Specified by:
onExpirein interfaceExoCache<K extends Serializable,V>- Parameters:
key- entry keyobj- value
-
onRemove
public void onRemove(K key, V obj)
Description copied from interface:ExoCacheOn remove entry event- Specified by:
onRemovein interfaceExoCache<K extends Serializable,V>- Parameters:
key- entry keyobj- value
-
onPut
public void onPut(K key, V obj)
Description copied from interface:ExoCacheOn put entry event- Specified by:
onPutin interfaceExoCache<K extends Serializable,V>- Parameters:
key- entry keyobj- value
-
onPutLocal
public void onPutLocal(K key, V obj)
Description copied from interface:ExoCacheOn put entry event- Specified by:
onPutLocalin interfaceExoCache<K extends Serializable,V>- Parameters:
key- entry keyobj- value
-
onGet
public void onGet(K key, V obj)
Description copied from interface:ExoCacheOn get entry event- Specified by:
onGetin interfaceExoCache<K extends Serializable,V>- Parameters:
key- entry keyobj- value
-
onClearCache
public void onClearCache()
Description copied from interface:ExoCacheon clear cache event- Specified by:
onClearCachein interfaceExoCache<K extends Serializable,V>
-
getListeners
public List<ListenerContext<K,V>> getListeners()
-
-