Interface Cache
-
- All Known Implementing Classes:
DefaultCache,NoOpCache
public interface Cache
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Tget(String id, Function<? super String,T> mappingFunction)Returns the value associated with the given id.<T> TgetIfPresent(String id)Returns the value associated with the given id if it exists in the cache.voidinvalidate(String id)Invalidates the cache entry mapped to given id.voidinvalidateAll()Invalidates all cache entries.voidput(String id, Object value)Adds or replaces a value in the cache.
-
-
-
Method Detail
-
put
void put(String id, Object value)
Adds or replaces a value in the cache.- Parameters:
id- The object idvalue- The value to cache
-
get
<T> T get(String id, Function<? super String,T> mappingFunction)
Returns the value associated with the given id. If there is no association, the mapping function is used to calculate a value. This value will be stored in the cache.- Type Parameters:
T- the type of object to return from the cache- Parameters:
id- The object idmappingFunction- The function to compute a value if the cache is not in the cache- Returns:
- The value associated with given id
-
getIfPresent
<T> T getIfPresent(String id)
Returns the value associated with the given id if it exists in the cache. If there is no association,nullis returned.- Type Parameters:
T- the type of object to return from the cache- Parameters:
id- The object id- Returns:
- The value associated with given id
-
invalidate
void invalidate(String id)
Invalidates the cache entry mapped to given id.
-
invalidateAll
void invalidateAll()
Invalidates all cache entries.
-
-