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 
    An EventPublisher which can be used to register event consumers.
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    computeIfAbsent(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.
     
    static <K, V> Cache<K,V>
    of(javax.cache.Cache<K,V> cache)
    Creates a Retry with default configuration.
  • Method Details

    • 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 key
      V - 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 key
      R - the type of value
      Parameters:
      cache - the Cache
      supplier - the original Supplier
      Returns:
      a supplier which is secured by a CircuitBreaker.
    • decorateSupplier

      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. Otherwise it calls the Supplier.
      Type Parameters:
      K - the type of key
      R - the type of value
      Parameters:
      cache - the Cache
      supplier - 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 key
      R - the type of value
      Parameters:
      cache - the Cache
      callable - 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

      V computeIfAbsent(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. 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 associated
      supplier - 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