Package oshi.util

Class Memoizer

java.lang.Object
oshi.util.Memoizer

@ThreadSafe public final class Memoizer extends Object
A memoized function stores the output corresponding to some set of specific inputs. Subsequent calls with remembered inputs return the remembered result rather than recalculating it.
  • Method Details

    • defaultExpiration

      public static long defaultExpiration()
      Default exipiration of memoized values in nanoseconds, which will refresh after this time elapses. Update by setting GlobalConfig property oshi.util.memoizer.expiration to a value in milliseconds.
      Returns:
      The number of nanoseconds to keep memoized values before refreshing
    • memoize

      public static <T> Supplier<T> memoize(Supplier<T> original, long ttlNanos)
      Store a supplier in a delegate function to be computed once, and only again after time to live (ttl) has expired.
      Type Parameters:
      T - The type of object supplied
      Parameters:
      original - The Supplier to memoize
      ttlNanos - Time in nanoseconds to retain calculation. If negative, retain indefinitely.
      Returns:
      A memoized version of the supplier
    • memoize

      public static <T> Supplier<T> memoize(Supplier<T> original)
      Store a supplier in a delegate function to be computed only once.
      Type Parameters:
      T - The type of object supplied
      Parameters:
      original - The Supplier to memoize
      Returns:
      A memoized version of the supplier