Class CachedValue<T>

java.lang.Object
org.moddingx.libx.util.lazy.CachedValue<T>

public class CachedValue<T> extends Object
A lazy value that is resolved when it is first used. However, this one can be invalidated, which causes it to recompute the value next time.
  • Constructor Details

    • CachedValue

      public CachedValue(@Nonnull Supplier<? extends T> supplier)
      Creates a new cached value.
  • Method Details

    • get

      public T get()
      Gets the value. If currently invalid, computes the value.
    • copy

      public CachedValue<T> copy()
      Returns a new cached value. If this cached value is currently valid, the new cached value will include the currently valid value. After that both values can be invalidated independent of each other.
    • invalidate

      public void invalidate()
      Invalidates the cached value.