Package oshi.util
Class Memoizer
- java.lang.Object
-
- oshi.util.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()
-
-
-
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 settingGlobalConfig
propertyoshi.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
- TheSupplier
to memoizettlNanos
- 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
- TheSupplier
to memoize- Returns:
- A memoized version of the supplier
-
-