Class RefreshingMemoizingSupplier<T>

  • All Implemented Interfaces:
    Memoize<T>, java.util.function.Supplier<T>

    class RefreshingMemoizingSupplier<T>
    extends java.lang.Object
    implements Memoize<T>
    The object can exist in one of two states:
    • expired which means that System.nanoTime is greater than timebound. memoized may hold an expired value or null. The object transitions to this state when time_to_live elapses. This is the initial state. From this state, the object transitions to valued when @{code get} is called.
    • valued which means that System.nanoTime is less than timebound. memoized holds the current value.
    • Constructor Summary

      Constructors 
      Constructor Description
      RefreshingMemoizingSupplier​(java.util.function.Supplier<? extends T> supplier, long time_to_live, java.util.concurrent.TimeUnit unit)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()  
      T peek()
      Peek the value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • supplier

        private final java.util.function.Supplier<? extends T> supplier
      • time_to_live

        private final long time_to_live
      • timebound

        private volatile long timebound
      • memoized

        private T memoized
    • Constructor Detail

      • RefreshingMemoizingSupplier

        RefreshingMemoizingSupplier​(java.util.function.Supplier<? extends T> supplier,
                                    long time_to_live,
                                    java.util.concurrent.TimeUnit unit)
    • Method Detail

      • get

        public T get()
        Specified by:
        get in interface java.util.function.Supplier<T>
      • peek

        public T peek()
        Description copied from interface: Memoize
        Peek the value.

        This method will not result in a call to the source supplier.

        Specified by:
        peek in interface Memoize<T>
        Returns:
        The value if a value is memoized; otherwise null.