Class LocalAsyncLoadingCache.LoadingCacheView

java.lang.Object
com.github.benmanes.caffeine.cache.LocalAsyncLoadingCache.LoadingCacheView
All Implemented Interfaces:
Cache<K,V>, LoadingCache<K,V>, Serializable
Enclosing class:
LocalAsyncLoadingCache<C extends LocalCache<K,CompletableFuture<V>>,K,V>

final class LocalAsyncLoadingCache.LoadingCacheView extends Object implements LoadingCache<K,V>, Serializable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a view of the entries stored in this cache as a thread-safe map.
    void
    Performs any pending maintenance operations needed by the cache.
    long
    Returns the approximate number of entries in this cache.
    get(K key)
    Returns the value associated with the key in this cache, obtaining that value from CacheLoader.load(Object) if necessary.
    get(K key, Function<? super K,? extends V> mappingFunction)
    Returns the value associated with the key in this cache, obtaining that value from the mappingFunction if necessary.
    getAll(Iterable<? extends K> keys)
    Returns a map of the values associated with the keys, creating or retrieving those values if necessary.
    Returns a map of the values associated with the keys in this cache.
    Returns the value associated with the key in this cache, or null if there is no cached value for the key.
    (package private) LocalAsyncLoadingCache<C,K,V>
    A test-only method for validation.
    void
    Discards any cached value for the key.
    void
    Discards all entries in the cache.
    void
    Discards any cached values for the keys.
    Returns access to inspect and perform low-level operations on this cache based on its runtime characteristics.
    void
    put(K key, V value)
    Associates the value with the key in this cache.
    void
    putAll(Map<? extends K,? extends V> map)
    Copies all of the mappings from the specified map to the cache.
    void
    refresh(K key)
    Loads a new value for the key, asynchronously.
    Returns a current snapshot of this cache's cumulative statistics.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • LoadingCacheView

      LoadingCacheView()
  • Method Details

    • getOuter

      A test-only method for validation.
    • getIfPresent

      public V getIfPresent(Object key)
      Description copied from interface: Cache
      Returns the value associated with the key in this cache, or null if there is no cached value for the key.
      Specified by:
      getIfPresent in interface Cache<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
    • getAllPresent

      public Map<K,V> getAllPresent(Iterable<?> keys)
      Description copied from interface: Cache
      Returns a map of the values associated with the keys in this cache. The returned map will only contain entries which are already present in the cache.
      Specified by:
      getAllPresent in interface Cache<K,V>
      Parameters:
      keys - the keys whose associated values are to be returned
      Returns:
      the unmodifiable mapping of keys to values for the specified keys found in this cache
    • get

      public V get(K key, Function<? super K,? extends V> mappingFunction)
      Description copied from interface: Cache
      Returns the value associated with the key in this cache, obtaining that value from the mappingFunction if necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern.

      If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this cache unless null. The entire method invocation is performed atomically, so the function is applied at most once per key. Some attempted update operations on this cache by other threads may be blocked while the computation is in progress, so the computation should be short and simple, and must not attempt to update any other mappings of this cache.

      Warning: as with CacheLoader.load(K), mappingFunction must not attempt to update any other mappings of this cache.

      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - the key with which the specified value is to be associated
      mappingFunction - the function to compute a value
      Returns:
      the current (existing or computed) value associated with the specified key, or null if the computed value is null
    • get

      public V get(K key)
      Description copied from interface: LoadingCache
      Returns the value associated with the key in this cache, obtaining that value from CacheLoader.load(Object) if necessary.

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

      If the specified key is not already associated with a value, attempts to compute its value and enters it into this cache unless null. The entire method invocation is performed atomically, so the function is applied at most once per key. Some attempted update operations on this cache by other threads may be blocked while the computation is in progress, so the computation should be short and simple, and must not attempt to update any other mappings of this cache.

      Specified by:
      get in interface LoadingCache<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      Returns:
      the current (existing or computed) value associated with the specified key, or null if the computed value is null
    • getAll

      public Map<K,V> getAll(Iterable<? extends K> keys)
      Description copied from interface: LoadingCache
      Returns a map of the values associated with the keys, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with the newly loaded entries; it will never contain null keys or values.

      Caches loaded by a CacheLoader will issue a single request to CacheLoader.loadAll(java.lang.Iterable<? extends K>) for all keys which are not already present in the cache. All entries returned by CacheLoader.loadAll(java.lang.Iterable<? extends K>) will be stored in the cache, over-writing any previously cached values. If another call to LoadingCache.get(K) tries to load the value for a key in keys, implementations may either have that thread load the entry or simply wait for this thread to finish and returns the loaded value. In the case of overlapping non-blocking loads, the last load to complete will replace the existing entry. Note that multiple threads can concurrently load values for distinct keys.

      Note that duplicate elements in keys, as determined by Object.equals(java.lang.Object), will be ignored.

      Specified by:
      getAll in interface LoadingCache<K,V>
      Parameters:
      keys - the keys whose associated values are to be returned
      Returns:
      the unmodifiable mapping of keys to values for the specified keys in this cache
    • put

      public void put(K key, V value)
      Description copied from interface: Cache
      Associates the value with the key in this cache. If the cache previously contained a value associated with the key, the old value is replaced by the new value.

      Prefer Cache.get(Object, Function) when using the conventional "if cached, return; otherwise create, cache and return" pattern.

      Specified by:
      put in interface Cache<K,V>
      Parameters:
      key - the key with which the specified value is to be associated
      value - value to be associated with the specified key
    • putAll

      public void putAll(Map<? extends K,? extends V> map)
      Description copied from interface: Cache
      Copies all of the mappings from the specified map to the cache. The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
      Specified by:
      putAll in interface Cache<K,V>
      Parameters:
      map - the mappings to be stored in this cache
    • invalidate

      public void invalidate(Object key)
      Description copied from interface: Cache
      Discards any cached value for the key. The behavior of this operation is undefined for an entry that is being loaded and is otherwise not present.
      Specified by:
      invalidate in interface Cache<K,V>
      Parameters:
      key - the key whose mapping is to be removed from the cache
    • invalidateAll

      public void invalidateAll(Iterable<?> keys)
      Description copied from interface: Cache
      Discards any cached values for the keys. The behavior of this operation is undefined for an entry that is being loaded and is otherwise not present.
      Specified by:
      invalidateAll in interface Cache<K,V>
      Parameters:
      keys - the keys whose associated values are to be removed
    • invalidateAll

      public void invalidateAll()
      Description copied from interface: Cache
      Discards all entries in the cache. The behavior of this operation is undefined for an entry that is being loaded and is otherwise not present.
      Specified by:
      invalidateAll in interface Cache<K,V>
    • estimatedSize

      public long estimatedSize()
      Description copied from interface: Cache
      Returns the approximate number of entries in this cache. The value returned is an estimate; the actual count may differ if there are concurrent insertions or removals, or if some entries are pending removal due to expiration or weak/soft reference collection. In the case of stale entries this inaccuracy can be mitigated by performing a Cache.cleanUp() first.
      Specified by:
      estimatedSize in interface Cache<K,V>
      Returns:
      the estimated number of mappings
    • stats

      public CacheStats stats()
      Description copied from interface: Cache
      Returns a current snapshot of this cache's cumulative statistics. All statistics are initialized to zero, and are monotonically increasing over the lifetime of the cache.

      Due to the performance penalty of maintaining statistics, some implementations may not record the usage history immediately or at all.

      Specified by:
      stats in interface Cache<K,V>
      Returns:
      the current snapshot of the statistics of this cache
    • cleanUp

      public void cleanUp()
      Description copied from interface: Cache
      Performs any pending maintenance operations needed by the cache. Exactly which activities are performed -- if any -- is implementation-dependent.
      Specified by:
      cleanUp in interface Cache<K,V>
    • refresh

      public void refresh(K key)
      Description copied from interface: LoadingCache
      Loads a new value for the key, 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 the key, and CacheLoader.load(K) otherwise. Loading is asynchronous by delegating to the default executor.

      Specified by:
      refresh in interface LoadingCache<K,V>
      Parameters:
      key - key with which a value may be associated
    • policy

      public Policy<K,V> policy()
      Description copied from interface: Cache
      Returns access to inspect and perform low-level operations on this cache based on its runtime characteristics. These operations are optional and dependent on how the cache was constructed and what abilities the implementation exposes.
      Specified by:
      policy in interface Cache<K,V>
      Returns:
      access to inspect and perform advanced operations based on the cache's characteristics
    • asMap

      public ConcurrentMap<K,V> asMap()
      Description copied from interface: Cache
      Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache.

      Iterators from the returned map are at least weakly consistent: they are safe for concurrent use, but if the cache is modified (including by eviction) after the iterator is created, it is undefined which of the changes (if any) will be reflected in that iterator.

      Specified by:
      asMap in interface Cache<K,V>
      Returns:
      a thread-safe view of this cache supporting all of the optional Map operations