Interface CachedReference<V>


@PublicApi public interface CachedReference<V>
A Resettable reference.
Since:
2.0
  • Method Details

    • get

      @Nonnull V get()
      Gets a value from the cache.
      Returns:
      the cached value
    • reset

      void reset()
      Resets (clears/invalidates) this reference.
    • isPresent

      boolean isPresent()
      Checks if there is currently a value in the cache.

      Note that cache entries could expire at any time, meaning that even after this method returns true, the reference may still have to be reinitialized on the next call to get().

      Returns:
      true iff get() would return a reference without invoking the underlying supplier.
      Since:
      5.1
    • getIfPresent

      @Nonnull Optional<V> getIfPresent()
      Checks if there is currently a value in the cache, and if so returns it.

      Note that cache entries could expire at any time, meaning that even if this method returns a value, the reference may still have to be reinitialized on the next call to get().

      Returns:
      some value iff get() would return a reference without invoking the underyling supplier, otherwise empty.
      Since:
      5.1
    • addListener

      void addListener(@Nonnull CachedReferenceListener<V> listener, boolean includeValues)
      Parameters:
      listener - the listener
      includeValues - if the events sent to this listener will include old/new value. This can be used in cases when the cost of finding these values is big (network sync) but the listener is not interested in the concrete values for events its getting. The support for this parameter is optional and implementation dependent
      Throws:
      UnsupportedOperationException - if not supported
      Since:
      2.4
    • removeListener

      void removeListener(@Nonnull CachedReferenceListener<V> listener)
      Parameters:
      listener - the listener
      Throws:
      UnsupportedOperationException - if not supported
      Since:
      2.4