Class MemoizedResult<R>

java.lang.Object
io.deephaven.engine.table.impl.MemoizedResult<R>
Type Parameters:
R - the type of the result

public class MemoizedResult<R> extends Object
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 on this object's monitor until the computation is complete.

  • Constructor Details

    • MemoizedResult

      public MemoizedResult()
  • Method Details

    • getOrCompute

      public R 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. Otherwise, return the cached value.
      Parameters:
      operation - the Supplier for our desired result
      Returns:
      the cached or newly computed value
    • getIfValid

      @Nullable protected R 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)