Class InvalidationExoCache<K extends Serializable,V>
- java.lang.Object
-
- org.exoplatform.services.cache.invalidation.InvalidationExoCache<K,V>
-
- All Implemented Interfaces:
CacheListener<K,HashCode<V>>,ExoCache<K,V>
public class InvalidationExoCache<K extends Serializable,V> extends Object implements ExoCache<K,V>, CacheListener<K,HashCode<V>>
This eXo cache type is a decorator allowing ExoCache instances that have big values or non serializable values to be replicated thanks to an invalidation mechanism. To prevent infinite loop described below, we replicate the hash code of the value such that if the hash code is the same, we don't invalidate the value locally- Cluster node #1 puts (key1, value1) into the cache
- On cluster node #2 key1 is invalidated by the put call in node #1
- Node #2 re-loads key1 and puts (key1, value1) into the cache
- On cluster node #1 key1 is invalidated, so we get back to step #1
- Version:
- $Id$
- Author:
- Nicolas Filotto
-
-
Constructor Summary
Constructors Constructor Description InvalidationExoCache(ExoCache<K,V> delegate)InvalidationExoCache(ExoCache<K,V> delegate, int concurrencyLevel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCacheListener(CacheListener<? super K,? super V> listener)Add a listener.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 labellonggetLiveTime()Returns the maximum life time of an entry in the cache.intgetMaxSize()Returns the maximum capacity of the cache.StringgetName()Returns the cache namebooleanisLogEnabled()voidonClearCache(CacheListenerContext context)The cache is globally cleared.voidonExpire(CacheListenerContext context, K key, HashCode<V> obj)An entry is expired from the cache.voidonGet(CacheListenerContext context, K key, HashCode<V> obj)An entry is retrieved from the cache.voidonPut(CacheListenerContext context, K key, HashCode<V> obj)An entry is inserted in the cache.voidonRemove(CacheListenerContext context, K key, HashCode<V> obj)An entry is removed from the cache.voidput(K key, V value)Performs a put in the cache.voidputLocal(K key, V value)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 key)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.voidremoveLocal(Serializable key)Removes an entry from the cache local mode (avoid replication).voidselect(CachedObjectSelector<? super K,? super V> selector)Selects a subset of the cache.voidsetLabel(String s)Sets the cache labelvoidsetLiveTime(long period)Sets the maximum life time of an entry in the cache.voidsetLogEnabled(boolean b)voidsetMaxSize(int max)Sets the maximum capacity of the cache.voidsetName(String name)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.CacheListener
onPutLocal
-
Methods inherited from interface org.exoplatform.services.cache.ExoCache
onClearCache, onExpire, onGet, onPut, onPutLocal, onRemove, putAsyncMap
-
-
-
-
Constructor Detail
-
InvalidationExoCache
public InvalidationExoCache(ExoCache<K,V> delegate)
- Parameters:
delegate- the underneath eXo cache instance, we assume that the eXo cache implementation behind is fully functional.
-
InvalidationExoCache
public InvalidationExoCache(ExoCache<K,V> delegate, int concurrencyLevel)
- Parameters:
delegate- the underneath eXo cache instance, we assume that the eXo cache implementation behind is fully functional.concurrencyLevel- the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:ExoCacheReturns the cache name- Specified by:
getNamein interfaceExoCache<K extends Serializable,V>- Returns:
- the cache name
- See Also:
ExoCache.getName()
-
setName
public void setName(String name)
Description copied from interface:ExoCacheSets the cache name.- Specified by:
setNamein interfaceExoCache<K extends Serializable,V>- Parameters:
name- the cache name- See Also:
ExoCache.setName(java.lang.String)
-
getLabel
public String getLabel()
Description copied from interface:ExoCacheReturns the cache label- Specified by:
getLabelin interfaceExoCache<K extends Serializable,V>- Returns:
- the cache label
- See Also:
ExoCache.getLabel()
-
setLabel
public void setLabel(String s)
Description copied from interface:ExoCacheSets the cache label- Specified by:
setLabelin interfaceExoCache<K extends Serializable,V>- Parameters:
s- the cache label- See Also:
ExoCache.setLabel(java.lang.String)
-
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
- See Also:
ExoCache.get(java.io.Serializable)
-
remove
public V remove(Serializable key) throws NullPointerException
Description copied from interface:ExoCacheRemoves an entry from the cache.- Specified by:
removein interfaceExoCache<K extends Serializable,V>- Parameters:
key- the cache key- Returns:
- the previously cached value or null if no entry existed or that entry value was evaluated to null
- Throws:
NullPointerException- if the provided key is null- See Also:
ExoCache.remove(java.io.Serializable)
-
removeLocal
public void removeLocal(Serializable key) throws NullPointerException
Description copied from interface:ExoCacheRemoves an entry from the cache local mode (avoid replication).- Specified by:
removeLocalin interfaceExoCache<K extends Serializable,V>- Parameters:
key- the cache key- Throws:
NullPointerException- if the provided key is null- See Also:
ExoCache.remove(java.io.Serializable)
-
put
public void put(K key, V value) throws NullPointerException
Description copied from interface:ExoCachePerforms a put in the cache.- Specified by:
putin interfaceExoCache<K extends Serializable,V>- Parameters:
key- the cache keyvalue- the cached value- Throws:
NullPointerException- if the key is null- See Also:
ExoCache.put(java.io.Serializable, java.lang.Object)
-
putLocal
public void putLocal(K key, V value) throws NullPointerException
Description copied from interface:ExoCachePerforms a put in the cache local mode (avoid replication).- Specified by:
putLocalin interfaceExoCache<K extends Serializable,V>- Parameters:
key- the cache keyvalue- the cached value- Throws:
NullPointerException- if the key is null
-
putMap
public void putMap(Map<? extends K,? extends V> objs) throws IllegalArgumentException
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- Throws:
IllegalArgumentException- if the provided map contains a null key- See Also:
ExoCache.putMap(java.util.Map)
-
clearCache
public void clearCache()
Description copied from interface:ExoCacheClears the cache.- Specified by:
clearCachein interfaceExoCache<K extends Serializable,V>- See Also:
ExoCache.clearCache()
-
select
public void select(CachedObjectSelector<? super K,? super V> selector) throws Exception
Description copied from interface:ExoCacheSelects a subset of the cache.- Specified by:
selectin interfaceExoCache<K extends Serializable,V>- Parameters:
selector- the selector- Throws:
Exception- any exception- See Also:
ExoCache.select(org.exoplatform.services.cache.CachedObjectSelector)
-
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
- See Also:
ExoCache.getCacheSize()
-
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
- See Also:
ExoCache.getMaxSize()
-
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- See Also:
ExoCache.setMaxSize(int)
-
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
- See Also:
ExoCache.getLiveTime()
-
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- See Also:
ExoCache.setLiveTime(long)
-
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
- See Also:
ExoCache.getCacheHit()
-
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
- See Also:
ExoCache.getCacheMiss()
-
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
- See Also:
ExoCache.getCachedObjects()
-
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
- See Also:
ExoCache.removeCachedObjects()
-
addCacheListener
public void addCacheListener(CacheListener<? super K,? super V> listener) throws IllegalArgumentException
Description copied from interface:ExoCacheAdd a listener.- Specified by:
addCacheListenerin interfaceExoCache<K extends Serializable,V>- Parameters:
listener- the listener to add- Throws:
IllegalArgumentException- See Also:
ExoCache.addCacheListener(org.exoplatform.services.cache.CacheListener)
-
isLogEnabled
public boolean isLogEnabled()
- Specified by:
isLogEnabledin interfaceExoCache<K extends Serializable,V>- See Also:
ExoCache.isLogEnabled()
-
setLogEnabled
public void setLogEnabled(boolean b)
- Specified by:
setLogEnabledin interfaceExoCache<K extends Serializable,V>- See Also:
ExoCache.setLogEnabled(boolean)
-
onExpire
public void onExpire(CacheListenerContext context, K key, HashCode<V> obj) throws Exception
An entry is expired from the cache.- Specified by:
onExpirein interfaceCacheListener<K extends Serializable,V>- Parameters:
context- the listener contextkey- the entry keyobj- the entry value- Throws:
Exception- any exception
-
onRemove
public void onRemove(CacheListenerContext context, K key, HashCode<V> obj) throws Exception
An entry is removed from the cache.- Specified by:
onRemovein interfaceCacheListener<K extends Serializable,V>- Parameters:
context- the listener contextkey- the entry keyobj- the entry value- Throws:
Exception- any exception
-
onPut
public void onPut(CacheListenerContext context, K key, HashCode<V> obj) throws Exception
An entry is inserted in the cache.- Specified by:
onPutin interfaceCacheListener<K extends Serializable,V>- Parameters:
context- the listener contextkey- the entry keyobj- the entry value- Throws:
Exception- any exception
-
onGet
public void onGet(CacheListenerContext context, K key, HashCode<V> obj) throws Exception
An entry is retrieved from the cache.- Specified by:
onGetin interfaceCacheListener<K extends Serializable,V>- Parameters:
context- the listener contextkey- the entry keyobj- the entry value- Throws:
Exception- any exception
-
onClearCache
public void onClearCache(CacheListenerContext context) throws Exception
Description copied from interface:CacheListenerThe cache is globally cleared.- Specified by:
onClearCachein interfaceCacheListener<K extends Serializable,V>- Parameters:
context- the listener context- Throws:
Exception- any exception- See Also:
CacheListener.onClearCache(org.exoplatform.services.cache.CacheListenerContext)
-
-