Package oshi.util

Class Memoizer


  • @ThreadSafe
    public final class Memoizer
    extends java.lang.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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.function.Supplier<java.lang.Long> DEFAULT_EXPIRATION_NANOS  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Memoizer()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long defaultExpiration()
      Default exipiration of memoized values in nanoseconds, which will refresh after this time elapses.
      static <T> java.util.function.Supplier<T> memoize​(java.util.function.Supplier<T> original)
      Store a supplier in a delegate function to be computed only once.
      static <T> java.util.function.Supplier<T> memoize​(java.util.function.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.
      private static long queryExpirationConfig()  
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_EXPIRATION_NANOS

        private static final java.util.function.Supplier<java.lang.Long> DEFAULT_EXPIRATION_NANOS
    • Constructor Detail

      • Memoizer

        private Memoizer()
    • Method Detail

      • queryExpirationConfig

        private static long queryExpirationConfig()
      • 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> java.util.function.Supplier<T> memoize​(java.util.function.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> java.util.function.Supplier<T> memoize​(java.util.function.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