/** * Creates a functions which returns a value from a cache, if it exists. * Otherwise it calls the Callable. * * @param cache the Cache * @param callable the original Callable * @param <K> the type of key * @param <R> the type of value * @return a supplier which is secured by a CircuitBreaker. */ static <K, R> CheckedFunction1<K, R> decorateCallable(Cache<K, R> cache, Callable<R> callable){ return (K cacheKey) -> cache.computeIfAbsent(cacheKey, callable::call); }
/** * Creates a functions which returns a value from a cache, if it exists. * Otherwise it calls the Supplier. * * @param cache the Cache * @param supplier the original Supplier * @param <K> the type of key * @param <R> the type of value * @return a supplier which is secured by a CircuitBreaker. */ static <K, R> CheckedFunction1<K, R> decorateCheckedSupplier(Cache<K, R> cache, CheckedFunction0<R> supplier){ return (K cacheKey) -> cache.computeIfAbsent(cacheKey, supplier); }
/** * Creates a functions which returns a value from a cache, if it exists. * Otherwise it calls the Supplier. * * @param cache the Cache * @param supplier the original Supplier * @param <K> the type of key * @param <R> the type of value * @return a supplier which is secured by a CircuitBreaker. */ static <K, R> Function<K, R> decorateSupplier(Cache<K, R> cache, Supplier<R> supplier){ return (K cacheKey) -> cache.computeIfAbsent(cacheKey, supplier::get); }
/** * Creates a functions which returns a value from a cache, if it exists. * Otherwise it calls the Supplier. * * @param cache the Cache * @param supplier the original Supplier * @param <K> the type of key * @param <R> the type of value * @return a supplier which is secured by a CircuitBreaker. */ static <K, R> Function<K, R> decorateSupplier(Cache<K, R> cache, Supplier<R> supplier){ return (K cacheKey) -> cache.computeIfAbsent(cacheKey, supplier::get); }
/** * Creates a functions which returns a value from a cache, if it exists. * Otherwise it calls the Callable. * * @param cache the Cache * @param callable the original Callable * @param <K> the type of key * @param <R> the type of value * @return a supplier which is secured by a CircuitBreaker. */ static <K, R> CheckedFunction1<K, R> decorateCallable(Cache<K, R> cache, Callable<R> callable){ return (K cacheKey) -> cache.computeIfAbsent(cacheKey, callable::call); }
/** * Creates a functions which returns a value from a cache, if it exists. * Otherwise it calls the Supplier. * * @param cache the Cache * @param supplier the original Supplier * @param <K> the type of key * @param <R> the type of value * @return a supplier which is secured by a CircuitBreaker. */ static <K, R> CheckedFunction1<K, R> decorateCheckedSupplier(Cache<K, R> cache, CheckedFunction0<R> supplier){ return (K cacheKey) -> cache.computeIfAbsent(cacheKey, supplier); }