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.
-
Method Summary
Modifier and Type Method Description static longdefaultExpiration()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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
defaultExpiration
public static long defaultExpiration()Default exipiration of memoized values in nanoseconds, which will refresh after this time elapses. Update by settingGlobalConfigpropertyoshi.util.memoizer.expirationto 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- TheSupplierto 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- TheSupplierto memoize- Returns:
- A memoized version of the supplier
-