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
ConstructorsConstructorDescriptionInvalidationExoCache(ExoCache<K, V> delegate) InvalidationExoCache(ExoCache<K, V> delegate, int concurrencyLevel) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCacheListener(CacheListener<? super K, ? super V> listener) Add a listener.voidClears the cache.get(Serializable name) Performs a lookup operation.Returns a list of cached object that are considered as valid when the method is called.intReturns the number of time the cache was queried and a valid entry was returned.intReturns the number of time the cache was queried and no entry was returned.intReturns the number of entries in the cache.getLabel()Returns the cache labellongReturns the maximum life time of an entry in the cache.intReturns the maximum capacity of the cache.getName()Returns the cache namebooleanvoidonClearCache(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.voidPerforms a put in the cache.voidPerforms a put in the cache local mode (avoid replication).voidPerforms a put of all the entries provided by the map argument.remove(Serializable key) Removes an entry from the cache.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.voidSets 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.voidSets the cache name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.exoplatform.services.cache.CacheListener
onPutLocalMethods inherited from interface org.exoplatform.services.cache.ExoCache
onClearCache, onExpire, onGet, onPut, onPutLocal, onRemove, putAsyncMap
-
Constructor Details
-
InvalidationExoCache
- Parameters:
delegate- the underneath eXo cache instance, we assume that the eXo cache implementation behind is fully functional.
-
InvalidationExoCache
- 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 Details
-
getName
Description copied from interface:ExoCacheReturns the cache name- Specified by:
getNamein interfaceExoCache<K extends Serializable,V> - Returns:
- the cache name
- See Also:
-
setName
Description copied from interface:ExoCacheSets the cache name.- Specified by:
setNamein interfaceExoCache<K extends Serializable,V> - Parameters:
name- the cache name- See Also:
-
getLabel
Description copied from interface:ExoCacheReturns the cache label- Specified by:
getLabelin interfaceExoCache<K extends Serializable,V> - Returns:
- the cache label
- See Also:
-
setLabel
Description copied from interface:ExoCacheSets the cache label- Specified by:
setLabelin interfaceExoCache<K extends Serializable,V> - Parameters:
s- the cache label- See Also:
-
get
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:
-
remove
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:
-
removeLocal
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:
-
put
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:
-
putLocal
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
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:
-
clearCache
public void clearCache()Description copied from interface:ExoCacheClears the cache.- Specified by:
clearCachein interfaceExoCache<K extends Serializable,V> - See Also:
-
select
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
- See Also:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
addCacheListener
public void addCacheListener(CacheListener<? super K, ? super V> listener) throws IllegalArgumentExceptionDescription copied from interface:ExoCacheAdd a listener.- Specified by:
addCacheListenerin interfaceExoCache<K extends Serializable,V> - Parameters:
listener- the listener to add- Throws:
IllegalArgumentException- See Also:
-
isLogEnabled
public boolean isLogEnabled()- Specified by:
isLogEnabledin interfaceExoCache<K extends Serializable,V> - See Also:
-
setLogEnabled
public void setLogEnabled(boolean b) - Specified by:
setLogEnabledin interfaceExoCache<K extends Serializable,V> - See Also:
-
onExpire
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
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
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
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
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:
-