Class ExternalCache
java.lang.Object
org.silverpeas.kernel.cache.model.AbstractSimpleCache
org.silverpeas.kernel.cache.model.ExternalCache
- All Implemented Interfaces:
Cache,SimpleCache
A more complete cache provided by an external library. The cache loaded and used by the
ApplicationCacheAccessor have to extend this abstract
class.- Since:
- 11/09/13
- Author:
- Yohann Chastagnier
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a value and generates a unique mapping key from which the value can be retrieved later.Adds a value and generate a unique mapping key to be used to retrieve later the value.<T> TcomputeIfAbsent(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> TcomputeIfAbsent(Object key, Class<T> classType, Supplier<T> valueSupplier) Gets a typed element mapped with the specified key from the cache or computes it with the specified value supplier if no such key exists.voidPuts a value for a given key.voidPuts a new value for the given key and updates its time to live.Methods inherited from class org.silverpeas.kernel.cache.model.AbstractSimpleCache
add, get, getAllMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.silverpeas.kernel.cache.model.Cache
computeIfAbsent, put
-
Constructor Details
-
ExternalCache
public ExternalCache()
-
-
Method Details
-
add
Description copied from interface:CacheAdds a value and generates a unique mapping key from which the value can be retrieved later.- Specified by:
addin 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
Description copied from interface:CacheAdds 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:
addin 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
Description copied from interface:SimpleCachePuts a value for a given key. After 12 hours without be used the value is trashed.- Specified by:
putin interfaceSimpleCache- Parameters:
key- the key with which the object to put has to be mappedvalue- the object to put in the cache.
-
put
Description copied from interface:CachePuts a new value for the given key and updates its time to live.- Specified by:
putin 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
Description copied from interface:SimpleCacheGets a typed element mapped with the specified key from the cache or computes it with the specified value supplier if no such key exists. If an element exists for the given key but the object type doesn't match the expected one, a new computation is performed. If the element returned by the computation is null, then nothing is put into the cache. The value supplier should not modify this cache during computation.- Specified by:
computeIfAbsentin interfaceSimpleCache- Overrides:
computeIfAbsentin 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 there is no object to map with the specified key.
-
computeIfAbsent
public <T> T computeIfAbsent(Object key, Class<T> classType, int timeToLive, Supplier<T> valueSupplier) Description copied from interface:CacheGets 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:
computeIfAbsentin 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.
-