Package io.deephaven.engine.table.impl
Class MemoizedResult<R>
java.lang.Object
io.deephaven.engine.table.impl.MemoizedResult<R>
- Type Parameters:
R- the type of the result
An implementation class for a memoized result, which holds a weak reference.
If multiple callers invoke getOrCompute simultaneously; only one caller computes the result; the others block until the computation is complete. A caller that may not wait instead computes its own result, which is not cached.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected RGets the saved result, if it is valid.getOrCompute(Supplier<R> operation) If the reference does not already hold a valid cached value, then execute the provided operation to compute the value, cache it, and return it.getOrCompute(Supplier<R> operation, boolean mayWait) If the reference does not already hold a valid cached value, then execute the provided operation to compute the value, cache it, and return it.
-
Constructor Details
-
MemoizedResult
public MemoizedResult()
-
-
Method Details
-
getOrCompute
If the reference does not already hold a valid cached value, then execute the provided operation to compute the value, cache it, and return it. Otherwise, return the cached value.- Parameters:
operation- the Supplier for our desired result- Returns:
- the cached or newly computed value
-
getOrCompute
If the reference does not already hold a valid cached value, then execute the provided operation to compute the value, cache it, and return it. Otherwise, return the cached value.- Parameters:
operation- the Supplier for our desired resultmayWait- Whether the caller may wait for a computation in progress on another thread; a caller that may not computes its own result while another computation is in progress, and that result is not cached- Returns:
- the cached or newly computed value
-
getIfValid
Gets the saved result, if it is valid. To determine liveness, the result is managed with the current scope before being returned. If the result is not valid, then null is returned.- Returns:
- the result, managed with the current scope (or null if not valid)
-