Package org.silverpeas.core.cache.model
Class AbstractSimpleCache
- java.lang.Object
-
- org.silverpeas.core.cache.model.AbstractSimpleCache
-
- All Implemented Interfaces:
SimpleCache
- Direct Known Subclasses:
AbstractCache
public abstract class AbstractSimpleCache extends Object implements SimpleCache
User: Yohann Chastagnier Date: 25/10/13
-
-
Constructor Summary
Constructors Constructor Description AbstractSimpleCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
add(Object value)
Adds a value and generate a unique key to retrieve later the value.<T> T
computeIfAbsent(Object key, Class<T> classType, Supplier<T> valueSupplier)
Gets a typed element from the cache and computes it if it does not yet exist.<T> T
get(Object key, Class<T> classType)
Gets a typed element from the cache.
-
-
-
Method Detail
-
get
public <T> T get(Object key, Class<T> classType)
Description copied from interface:SimpleCache
Gets a typed element from the cache. Null is returned if an element exists for the given key but the object doesn't satisfy the expected type.- Specified by:
get
in interfaceSimpleCache
- Type Parameters:
T
- the concrete type of the object to get.- Parameters:
key
- the key with which the object to get is mapped in the cache.classType
- the class type the instance to get as to satisfy.- Returns:
- the object mapped with the key or null if either there is no object mapped with the specified key or the object doesn't satisfy the expected class type.
-
computeIfAbsent
public <T> T computeIfAbsent(Object key, Class<T> classType, Supplier<T> valueSupplier)
Description copied from interface:SimpleCache
Gets a typed element from the cache and computes it if it does not yet exist. If an element exists for the given key but the object type doesn't correspond, a new computation is performed.- Specified by:
computeIfAbsent
in interfaceSimpleCache
- Type Parameters:
T
- the concrete type of the object to get.- Parameters:
key
- the key with which the object to get is mapped in the cache.classType
- the class of the instance to get.valueSupplier
- the function that will computes the data to put into the cache.- Returns:
- the object mapped with the key or null if no there is no object mapped with the specified key.
-
add
public String add(Object value)
Description copied from interface:SimpleCache
Adds a value and generate a unique key to retrieve later the value. After 12 hours without be used the value is trashed.- Specified by:
add
in interfaceSimpleCache
- Parameters:
value
- the object to add in the cache.- Returns:
- the key with which the added object is mapped in the cache.
-
-