Package io.github.resilience4j.cache
Interface Cache<K,V>
- All Known Implementing Classes:
CacheImpl
public interface Cache<K,V>
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
An EventPublisher which can be used to register event consumers.static interface
-
Method Summary
Modifier and TypeMethodDescriptioncomputeIfAbsent
(K key, io.github.resilience4j.core.functions.CheckedSupplier<V> supplier) If the key is not already associated with a cached value, attempts to compute its value using the given supplier and puts it into the cache.static <K,
R> io.github.resilience4j.core.functions.CheckedFunction<K, R> decorateCallable
(Cache<K, R> cache, Callable<R> callable) Creates a functions which returns a value from a cache, if it exists.static <K,
R> io.github.resilience4j.core.functions.CheckedFunction<K, R> decorateCheckedSupplier
(Cache<K, R> cache, io.github.resilience4j.core.functions.CheckedSupplier<R> supplier) Creates a functions which returns a value from a cache, if it exists.static <K,
R> Function<K, R> decorateSupplier
(Cache<K, R> cache, Supplier<R> supplier) Creates a functions which returns a value from a cache, if it exists.Returns an EventPublisher which can be used to register event consumers.Returns the Metrics of this Cache.getName()
static <K,
V> Cache<K, V> of
(javax.cache.Cache<K, V> cache) Creates a Retry with default configuration.
-
Method Details
-
of
Creates a Retry with default configuration.- Type Parameters:
K
- the type of keyV
- the type of value- Parameters:
cache
- the wrapped JCache instance- Returns:
- a Cache
-
decorateCheckedSupplier
static <K,R> io.github.resilience4j.core.functions.CheckedFunction<K,R> decorateCheckedSupplier(Cache<K, R> cache, io.github.resilience4j.core.functions.CheckedSupplier<R> supplier) Creates a functions which returns a value from a cache, if it exists. Otherwise it calls the Supplier.- Type Parameters:
K
- the type of keyR
- the type of value- Parameters:
cache
- the Cachesupplier
- the original Supplier- Returns:
- a supplier which is secured by a CircuitBreaker.
-
decorateSupplier
Creates a functions which returns a value from a cache, if it exists. Otherwise it calls the Supplier.- Type Parameters:
K
- the type of keyR
- the type of value- Parameters:
cache
- the Cachesupplier
- the original Supplier- Returns:
- a supplier which is secured by a CircuitBreaker.
-
decorateCallable
static <K,R> io.github.resilience4j.core.functions.CheckedFunction<K,R> decorateCallable(Cache<K, R> cache, Callable<R> callable) Creates a functions which returns a value from a cache, if it exists. Otherwise it calls the Callable.- Type Parameters:
K
- the type of keyR
- the type of value- Parameters:
cache
- the Cachecallable
- the original Callable- Returns:
- a supplier which is secured by a CircuitBreaker.
-
getName
String getName()- Returns:
- the cache name
-
getMetrics
Cache.Metrics getMetrics()Returns the Metrics of this Cache.- Returns:
- the Metrics of this Cache
-
computeIfAbsent
If the key is not already associated with a cached value, attempts to compute its value using the given supplier and puts it into the cache. Otherwise it returns the cached value. If the function itself throws an (unchecked) exception, the exception is rethrown.- Parameters:
key
- key with which the specified value is to be associatedsupplier
- value to be associated with the specified key- Returns:
- cached value
-
getEventPublisher
Cache.EventPublisher getEventPublisher()Returns an EventPublisher which can be used to register event consumers.- Returns:
- an EventPublisher
-