Package org.exoplatform.services.cache
Interface ExoCache<K extends Serializable,V>
-
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of cached values
- All Known Implementing Classes:
AsyncInvalidationExoCache,ConcurrentFIFOExoCache,FIFOExoCache,InvalidationExoCache,SimpleExoCache,SimpleReplicatedExoCache
public interface ExoCache<K extends Serializable,V>Created by The eXo Platform SAS
A bare cache.- Author:
- Tuan Nguyen
- eXo level API
- Platform
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddCacheListener(CacheListener<? super K,? super V> listener)Add a listener.voidclearCache()Clears the cache.Vget(Serializable key)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()default voidonClearCache()on clear cache eventdefault voidonExpire(K key, V obj)On expire entry eventdefault voidonGet(K key, V obj)On get entry eventdefault voidonPut(K key, V obj)On put entry eventdefault voidonPutLocal(K key, V obj)On put entry eventdefault voidonRemove(K key, V obj)On remove entry eventvoidput(K key, V value)Performs a put in the cache.default voidputAsyncMap(Map<? extends K,? extends V> objs)Performs a put of all the entries provided by the map argument on asynchronous mode.default 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.default 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.
-
-
-
Method Detail
-
getName
String getName()
Returns the cache name- Returns:
- the cache name
-
setName
void setName(String name)
Sets the cache name.- Parameters:
name- the cache name
-
getLabel
String getLabel()
Returns the cache label- Returns:
- the cache label
-
setLabel
void setLabel(String s)
Sets the cache label- Parameters:
s- the cache label
-
get
V get(Serializable key)
Performs a lookup operation.- Parameters:
key- the cache key- Returns:
- the cached value which may be evaluated to null
-
remove
V remove(Serializable key) throws NullPointerException
Removes an entry from the cache.- 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
-
removeLocal
default void removeLocal(Serializable key) throws NullPointerException
Removes an entry from the cache local mode (avoid replication).- Parameters:
key- the cache key- Throws:
NullPointerException- if the provided key is null
-
put
void put(K key, V value) throws NullPointerException
Performs a put in the cache.- Parameters:
key- the cache keyvalue- the cached value- Throws:
NullPointerException- if the key is null
-
putLocal
default void putLocal(K key, V value) throws NullPointerException
Performs a put in the cache local mode (avoid replication).- Parameters:
key- the cache keyvalue- the cached value- Throws:
NullPointerException- if the key is null
-
putMap
void putMap(Map<? extends K,? extends V> objs) throws NullPointerException, IllegalArgumentException
Performs a put of all the entries provided by the map argument.- Parameters:
objs- the objects to put- Throws:
NullPointerException- if the provided argument is nullIllegalArgumentException- if the provided map contains a null key
-
putAsyncMap
default void putAsyncMap(Map<? extends K,? extends V> objs) throws NullPointerException, IllegalArgumentException
Performs a put of all the entries provided by the map argument on asynchronous mode.- Parameters:
objs- the objects to put- Throws:
NullPointerException- if the provided argument is nullIllegalArgumentException- if the provided map contains a null keyUnsupportedOperationException- if async put operation is not supported
-
clearCache
void clearCache()
Clears the cache.
-
select
void select(CachedObjectSelector<? super K,? super V> selector) throws Exception
Selects a subset of the cache.- Parameters:
selector- the selector- Throws:
Exception- any exception
-
getCacheSize
int getCacheSize()
Returns the number of entries in the cache.- Returns:
- the size of the cache
-
getMaxSize
int getMaxSize()
Returns the maximum capacity of the cache.- Returns:
- the maximum capacity
-
setMaxSize
void setMaxSize(int max)
Sets the maximum capacity of the cache.- Parameters:
max- the maximum capacity
-
getLiveTime
long getLiveTime()
Returns 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.- Returns:
- the live time
-
setLiveTime
void setLiveTime(long period)
Sets the maximum life time of an entry in the cache.- Parameters:
period- the live time
-
getCacheHit
int getCacheHit()
Returns the number of time the cache was queried and a valid entry was returned.- Returns:
- the cache hits
-
getCacheMiss
int getCacheMiss()
Returns the number of time the cache was queried and no entry was returned.- Returns:
- the cache misses
-
getCachedObjects
List<? extends V> getCachedObjects() throws Exception
Returns a list of cached object that are considered as valid when the method is called. Any non valid object will not be returned.- Returns:
- the list of cached objects
- Throws:
Exception- any exception
-
removeCachedObjects
List<? extends V> removeCachedObjects()
Clears 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.- Returns:
- the list of cached objects
-
addCacheListener
void addCacheListener(CacheListener<? super K,? super V> listener) throws NullPointerException
Add a listener.- Parameters:
listener- the listener to add- Throws:
NullPointerException- if the listener is null
-
onExpire
default void onExpire(K key, V obj)
On expire entry event- Parameters:
key- entry keyobj- value
-
onRemove
default void onRemove(K key, V obj)
On remove entry event- Parameters:
key- entry keyobj- value
-
onPutLocal
default void onPutLocal(K key, V obj)
On put entry event- Parameters:
key- entry keyobj- value
-
onClearCache
default void onClearCache()
on clear cache event
-
isLogEnabled
boolean isLogEnabled()
-
setLogEnabled
void setLogEnabled(boolean b)
-
-