Class AbstractSimpleCache
java.lang.Object
org.silverpeas.kernel.cache.model.AbstractSimpleCache
- All Implemented Interfaces:
SimpleCache
- Direct Known Subclasses:
ExternalCache,InMemoryCache
Common implementation of a
SimpleCache from which a more concrete solution can be
extended.- Since:
- 25/10/13
- Author:
- Yohann Chastagnier
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a value and generate a unique key to retrieve later the value.<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.<T> TGets a typed element from the cache.getAll()Gets the whole content of the cache.
-
Constructor Details
-
AbstractSimpleCache
public AbstractSimpleCache()
-
-
Method Details
-
get
Description copied from interface:SimpleCacheGets 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:
getin 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
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- 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.
-
add
Description copied from interface:SimpleCacheAdds a value and generate a unique key to retrieve later the value. After 12 hours without be used the value is trashed.- Specified by:
addin interfaceSimpleCache- Parameters:
value- the object to add in the cache.- Returns:
- the key with which the added object is mapped in the cache.
-
getAll
Gets the whole content of the cache.- Returns:
- a
Mapwith all the items in the cache, mapped each of them by their key.
-