Interface Cache
- All Superinterfaces:
SimpleCache
- All Known Implementing Classes:
ExternalCache
A cache is a storage mechanism to store intermediate data got from any subsystems or from
external services in order to retrieve them fastly and hence more efficiently. A cache is
dedicated to boost performance and to simplify scalability.
This interface defines a more complete cache by taking into account the time in which a data can be kept in the cache before expiration.
- Since:
- 11/09/13
- Author:
- Yohann Chastagnier
-
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, int timeToIdle, 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, int timeToLive, Supplier<T> valueSupplier) Gets a typed element from the cache and computes it if it does not yet exist.voidPuts a new value for the given key and updates its time to live.voidPuts a new value for the given key and updates both its time to live and its time to idle.Methods inherited from interface org.silverpeas.kernel.cache.model.SimpleCache
add, clear, computeIfAbsent, get, get, has, put, remove, remove
-
Method Details
-
add
Adds a value and generates a unique mapping key from which the value can be retrieved later.- 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
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.- 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
Puts a new value for the given key and updates its time to live.- 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.
-
put
Puts a new value for the given key and updates both its time to live and its time to idle. 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.- 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 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.
-
computeIfAbsent
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.- 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.
-
computeIfAbsent
<T> T computeIfAbsent(Object key, Class<T> classType, int timeToLive, int timeToIdle, Supplier<T> valueSupplier) 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.- 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.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.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.
-