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 until the computation is complete. A caller that may not wait instead computes its own result, which is not cached.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected R
    Gets 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • getOrCompute

      public R 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. Otherwise, return the cached value.
      Parameters:
      operation - the Supplier for our desired result
      mayWait - 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

      @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)