Class ForwardingLoadingCache<K,​V>

    • Method Detail

      • delegate

        protected abstract LoadingCache<K,​Vdelegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingCache<K,​V>
      • getUnchecked

        @CanIgnoreReturnValue
        public V getUnchecked​(K key)
        Description copied from interface: LoadingCache
        Returns the value associated with key in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes. Unlike LoadingCache.get(K), this method does not throw a checked exception, and thus should only be used in situations where checked exceptions are not thrown by the cache loader.

        If another call to LoadingCache.get(K) or LoadingCache.getUnchecked(K) is currently loading the value for key, simply waits for that thread to finish and returns its loaded value. Note that multiple threads can concurrently load values for distinct keys.

        Caches loaded by a CacheLoader will call CacheLoader.load(K) to load new values into the cache. Newly loaded values are added to the cache using Cache.asMap().putIfAbsent after loading has completed; if another value was associated with key while the new value was loading then a removal notification will be sent for the new value.

        Warning: this method silently converts checked exceptions to unchecked exceptions, and should not be used with cache loaders which throw checked exceptions. In such cases use LoadingCache.get(K) instead.

        Specified by:
        getUnchecked in interface LoadingCache<K,​V>
      • apply

        public V apply​(K key)
        Description copied from interface: Function
        Returns the result of applying this function to input. This method is generally expected, but not absolutely required, to have the following properties:
        • Its execution does not cause any observable side effects.
        • The computation is consistent with equals; that is, Objects.equal(a, b) implies that Objects.equal(function.apply(a), function.apply(b)).
        Specified by:
        apply in interface Function<K,​V>
        Specified by:
        apply in interface LoadingCache<K,​V>
      • refresh

        public void refresh​(K key)
        Description copied from interface: LoadingCache
        Loads a new value for key, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned by get(key) unless it is evicted. If the new value is loaded successfully it will replace the previous value in the cache; if an exception is thrown while refreshing the previous value will remain, and the exception will be logged (using Logger) and swallowed.

        Caches loaded by a CacheLoader will call CacheLoader.reload(K, V) if the cache currently contains a value for key, and CacheLoader.load(K) otherwise. Loading is asynchronous only if CacheLoader.reload(K, V) was overridden with an asynchronous implementation.

        Returns without doing anything if another thread is currently loading the value for key. If the cache loader associated with this cache performs refresh asynchronously then this method may return before refresh completes.

        Specified by:
        refresh in interface LoadingCache<K,​V>