Class CachedValue<T>

    • Method Detail

      • withInitial

        public static <T> CachedValue<T> withInitial​(Supplier<T> supplier)
        Creates a cached value. The value will be computed by invoking the given supplier when the get() method will be called the first time.
        Type Parameters:
        T - The type of the cached value
        Parameters:
        supplier - The supplier which will be invoked only once in order to compute the value to cache. The value must not be null
        Returns:
        The CachedValue
      • withExpiryDuration

        public static <T> CachedValue<T> withExpiryDuration​(Supplier<T> supplier,
                                                            Duration expiryDuration)
        Creates a cached value. The value will be computed by invoking the given supplier when the get() method will be called the very first time, and every first time after the given Duration is expired.
        Type Parameters:
        T - The type of the cached value
        Parameters:
        supplier - The supplier which will be invoked only once in order to compute the value to cache. The value must not be null
        expiryDuration - The expiry duration
        Returns:
        The CachedValue
      • get

        public T get()
        Returns the value. If it is the first time it is called, then it is computed by invoking the supplier function. Otherwise, the cached value is returned.
        Returns:
        the value
      • uncache

        public void uncache()
        Uncache the value. Mostly to force to re-compute the value.