Class CachingSupplier<T>

java.lang.Object
org.axonframework.conversion.CachingSupplier<T>
All Implemented Interfaces:
Supplier<T>

public class CachingSupplier<T> extends Object implements Supplier<T>
A Supplier that caches its result, useful if the supplier operation is expensive and expected to always yield the same result. This supplier can be used concurrently by multiple threads.
Author:
Rene de Waele
  • Method Details

    • of

      public static <T> CachingSupplier<T> of(T value)
      Factory method for a CachingSupplier that will supply the given value.

      This factory method should be used when the value is already available. Used this way this supplier can be serialized.

      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      value - the value to supply
      Returns:
      a CachingSupplier that supplies the given value
    • of

      public static <T> CachingSupplier<T> of(Supplier<T> supplier)
      Factory method for a CachingSupplier that delegates to the given supplier when asked to supply a value. If the given supplier is a CachingSupplier the instance is returned as is, if not a new CachingSupplier instance is created.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      supplier - supplier for which to cache the result
      Returns:
      a CachingSupplier based on given supplier
    • get

      public T get()
      Specified by:
      get in interface Supplier<T>