Interface LocalCache.ValueReference<K,V>

All Known Implementing Classes:
LocalCache.ComputingValueReference, LocalCache.LoadingValueReference, LocalCache.SoftValueReference, LocalCache.StrongValueReference, LocalCache.WeakValueReference, LocalCache.WeightedSoftValueReference, LocalCache.WeightedStrongValueReference, LocalCache.WeightedWeakValueReference
Enclosing class:
LocalCache<K,V>

static interface LocalCache.ValueReference<K,V>
A reference to a value.
  • Method Summary

    Modifier and Type
    Method
    Description
    copyFor(ReferenceQueue<V> queue, V value, ReferenceEntry<K,V> entry)
    Creates a copy of this reference for the given entry.
    get()
    Returns the value.
    Returns the entry associated with this value reference, or null if this value reference is independent of any entry.
    int
    Returns the weight of this entry.
    boolean
    Returns true if this reference contains an active value, meaning one that is still considered present in the cache.
    boolean
    Returns true if a new value is currently loading, regardless of whether there is an existing value.
    void
    notifyNewValue(V newValue)
    Notify pending loads that a new value was set.
    Waits for a value that may still be loading.
  • Method Details

    • get

      @CheckForNull V get()
      Returns the value. Does not block or throw exceptions.
    • waitForValue

      V waitForValue() throws ExecutionException
      Waits for a value that may still be loading. Unlike get(), this method can block (in the case of FutureValueReference).
      Throws:
      ExecutionException - if the loading thread throws an exception
      ExecutionError - if the loading thread throws an error
    • getWeight

      int getWeight()
      Returns the weight of this entry. This is assumed to be static between calls to setValue.
    • getEntry

      @CheckForNull ReferenceEntry<K,V> getEntry()
      Returns the entry associated with this value reference, or null if this value reference is independent of any entry.
    • copyFor

      LocalCache.ValueReference<K,V> copyFor(ReferenceQueue<V> queue, @CheckForNull V value, ReferenceEntry<K,V> entry)
      Creates a copy of this reference for the given entry.

      value may be null only for a loading reference.

    • notifyNewValue

      void notifyNewValue(@CheckForNull V newValue)
      Notify pending loads that a new value was set. This is only relevant to loading value references.
    • isLoading

      boolean isLoading()
      Returns true if a new value is currently loading, regardless of whether there is an existing value. It is assumed that the return value of this method is constant for any given ValueReference instance.
    • isActive

      boolean isActive()
      Returns true if this reference contains an active value, meaning one that is still considered present in the cache. Active values consist of live values, which are returned by cache lookups, and dead values, which have been evicted but awaiting removal. Non-active values consist strictly of loading values, though during refresh a value may be both active and loading.