Package org.silverpeas.core.cache.model
Class AbstractCache
- java.lang.Object
-
- org.silverpeas.core.cache.model.AbstractSimpleCache
-
- org.silverpeas.core.cache.model.AbstractCache
-
- All Implemented Interfaces:
Cache
,SimpleCache
public abstract class AbstractCache extends AbstractSimpleCache implements Cache
Implementation of the Cache that uses EhCache API. User: Yohann Chastagnier Date: 11/09/13
-
-
Constructor Summary
Constructors Constructor Description AbstractCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
add(Object value, int timeToLive)
Adds a value and generates a unique mapping key to be used to retrieve later the value.String
add(Object value, int timeToLive, int timeToIdle)
Adds a value and generate a unique mapping key to be used to retrieve later the value.<T> T
computeIfAbsent(Object key, Class<T> classType, int timeToLive, Supplier<T> valueSupplier)
Gets a typed element from the cache and computes it if it does not yet exist.<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.void
put(Object key, Object value)
Puts a value for a given key.void
put(Object key, Object value, int timeToLive)
Puts a new value for the given key and updates its time to live.-
Methods inherited from class org.silverpeas.core.cache.model.AbstractSimpleCache
add, get
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.cache.model.Cache
computeIfAbsent, put
-
-
-
-
Method Detail
-
add
public String add(Object value, int timeToLive)
Description copied from interface:Cache
Adds a value and generates a unique mapping key to be used to retrieve later the value.- Specified by:
add
in interfaceCache
- Parameters:
value
- an object to add into the cachetimeToLive
- the time to live in seconds of the value in the cache. After this time, the value expires and consequently it is removed from the cache. 0 = unlimited.- Returns:
- the key to which the added value is mapped in the cache
-
add
public String add(Object value, int timeToLive, int timeToIdle)
Description copied from interface:Cache
Adds a value and generate a unique mapping key to be used to retrieve later the value. When both the time to live and the time to idle are set, the lifetime of the value in the cache is initially bounded by the time to live except if the lifetime computed from the time to live at the last access of the value (access time plus the time to idle) exceeds this initial lifetime.- Specified by:
add
in interfaceCache
- Parameters:
value
- the object to add in the cache.timeToLive
- the time to live in seconds of the object in the cache. The time to live can be exceeded if the time to idle is set and the value is accessed after the time to live minus the time to idle. 0 = unlimited.timeToIdle
- the time to idle in seconds of the object in the cache between two accesses. With the time to live set, the time to idle is taken into account only once the time starting at the access time exceed the initial lifetime of the value computed from the time to live. After this time, the value expires and consequently it is remove from the cache. 0 = unlimited.- Returns:
- the key to which the added object is mapped in the cache
-
put
public void put(Object key, Object value)
Description copied from interface:SimpleCache
Puts a value for a given key. After 12 hours without be used the value is trashed.- Specified by:
put
in interfaceSimpleCache
- Parameters:
key
- the key with which the object to put has to be mappedvalue
- the object to put in the cache.
-
put
public void put(Object key, Object value, int timeToLive)
Description copied from interface:Cache
Puts a new value for the given key and updates its time to live.- Specified by:
put
in interfaceCache
- Parameters:
key
- the key with which the object to put has to be mapped.value
- the object to put in the cache.timeToLive
- the time to live in seconds of the value in the cache. After this time, the value expires and consequently it is removed from the cache. 0 = unlimited.
-
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
- Overrides:
computeIfAbsent
in classAbstractSimpleCache
- 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.
-
computeIfAbsent
public <T> T computeIfAbsent(Object key, Class<T> classType, int timeToLive, Supplier<T> valueSupplier)
Description copied from interface:Cache
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 interfaceCache
- 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.timeToLive
- the time to live in seconds of the object in the cache. The time to live can be exceeded if the time to idle is set and the value is accessed after the time to live minus the time to idle. 0 = unlimited.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.
-
-