Package io.github.resilience4j.cache
Interface Cache<K,V>
-
- All Known Implementing Classes:
CacheImpl
public interface Cache<K,V>
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Cache.EventPublisher
An EventPublisher which can be used to register event consumers.static interface
Cache.Metrics
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description V
computeIfAbsent(K key, io.vavr.CheckedFunction0<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.vavr.CheckedFunction1<K,R>decorateCallable(Cache<K,R> cache, java.util.concurrent.Callable<R> callable)
Creates a functions which returns a value from a cache, if it exists.static <K,R>
io.vavr.CheckedFunction1<K,R>decorateCheckedSupplier(Cache<K,R> cache, io.vavr.CheckedFunction0<R> supplier)
Creates a functions which returns a value from a cache, if it exists.static <K,R>
java.util.function.Function<K,R>decorateSupplier(Cache<K,R> cache, java.util.function.Supplier<R> supplier)
Creates a functions which returns a value from a cache, if it exists.Cache.EventPublisher
getEventPublisher()
Returns an EventPublisher which can be used to register event consumers.Cache.Metrics
getMetrics()
Returns the Metrics of this Cache.java.lang.String
getName()
static <K,V>
Cache<K,V>of(javax.cache.Cache<K,V> cache)
Creates a Retry with default configuration.
-
-
-
Method Detail
-
of
static <K,V> Cache<K,V> of(javax.cache.Cache<K,V> cache)
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.vavr.CheckedFunction1<K,R> decorateCheckedSupplier(Cache<K,R> cache, io.vavr.CheckedFunction0<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
static <K,R> java.util.function.Function<K,R> decorateSupplier(Cache<K,R> cache, java.util.function.Supplier<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.
-
decorateCallable
static <K,R> io.vavr.CheckedFunction1<K,R> decorateCallable(Cache<K,R> cache, java.util.concurrent.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
java.lang.String getName()
- Returns:
- the cache name
-
getMetrics
Cache.Metrics getMetrics()
Returns the Metrics of this Cache.- Returns:
- the Metrics of this Cache
-
computeIfAbsent
V computeIfAbsent(K key, io.vavr.CheckedFunction0<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. 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
-
-