Top Description Inners Fields Constructors Methods
com.github.benmanes.caffeine.guava

pack-priv final Class CaffeinatedGuavaLoadingCache<K, V>

extends CaffeinatedGuavaCache<K, V>
implements LoadingCache<K, V>
Class Inheritance
All Implemented Interfaces
com.google.common.cache.LoadingCache, com.google.common.base.Function, java.util.function.Function, com.google.common.cache.Cache
Annotations
@SuppressWarnings:PMD.ExceptionAsFlowControl, serial
Static Imports
java.util.Objects.requireNonNull

A Caffeine-backed loading cache through a Guava facade.
Author
[email protected] (Ben Manes)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final LoadingCache<K, V>
private static final ThreadLocal<Boolean>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public V
apply(K
the function argument
key
)

Implements com.google.common.cache.LoadingCache.apply.

Applies this function to the given argument.
public V
get(K key)

Implements com.google.common.cache.LoadingCache.get.

Returns the value associated with key in this cache, first loading that value if necessary.
public ImmutableMap<K, V>
getAll(Iterable<? extends K> keys)

Implements com.google.common.cache.LoadingCache.getAll.

Returns a map of the values associated with keys, creating or retrieving those values if necessary.
public V
getUnchecked(K key)

Implements com.google.common.cache.LoadingCache.getUnchecked.

Returns the value associated with key in this cache, first loading that value if necessary.
public void
refresh(K key)

Implements com.google.common.cache.LoadingCache.refresh.

Loads a new value for key, possibly asynchronously.
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaCache:
asMapcleanUpgetgetAllPresentgetIfPresentinvalidateinvalidateAllinvalidateAllputputAllsizestats

Field Detail

cacheback to summary
private final LoadingCache<K, V> cache

Hides com.github.benmanes.caffeine.guava.CaffeinatedGuavaCache.cache.

nullBulkLoadback to summary
private static final ThreadLocal<Boolean> nullBulkLoad
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.github.benmanes.caffeine.guava.CaffeinatedGuavaCache.serialVersionUID.

Constructor Detail

CaffeinatedGuavaLoadingCacheback to summary
pack-priv CaffeinatedGuavaLoadingCache(LoadingCache<K, V> cache)

Method Detail

applyback to summary
public V apply(K key)

Implements com.google.common.cache.LoadingCache.apply.

Doc from java.util.function.Function.apply.

Applies this function to the given argument.

Parameters
key:K

the function argument

Returns:V

the function result

Annotations
@Override
@SuppressWarnings:deprecation, NullAway
getback to summary
public V get(K key) throws ExecutionException

Implements com.google.common.cache.LoadingCache.get.

Doc from com.google.common.cache.LoadingCache.get.

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.

If another call to get or getUnchecked 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 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.

If the cache loader associated with this cache is known not to throw checked exceptions, then prefer getUnchecked over this method.

Annotations
@Override
@SuppressWarnings:NullAway, PMD.PreserveStackTrace
Exceptions
ExecutionException:
if a checked exception was thrown while loading the value. (ExecutionException is thrown even if computation was interrupted by an InterruptedException.)
getAllback to summary
public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException

Implements com.google.common.cache.LoadingCache.getAll.

Doc from com.google.common.cache.LoadingCache.getAll.

Returns a map of the values associated with keys, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with newly loaded entries; it will never contain null keys or values.

Caches loaded by a CacheLoader will issue a single request to CacheLoader#loadAll for all keys which are not already present in the cache. All entries returned by CacheLoader#loadAll will be stored in the cache, over-writing any previously cached values. This method will throw an exception if CacheLoader#loadAll returns null, returns a map containing null keys or values, or fails to return an entry for each requested key.

Note that duplicate elements in keys, as determined by Object#equals, will be ignored.

Annotations
@Override
@SuppressWarnings:CatchingUnchecked, PMD.AvoidCatchingNPE, PMD.PreserveStackTrace
Exceptions
ExecutionException:
if a checked exception was thrown while loading the value. (ExecutionException is thrown even if computation was interrupted by an InterruptedException.)
getUncheckedback to summary
public V getUnchecked(K key)

Implements com.google.common.cache.LoadingCache.getUnchecked.

Doc from com.google.common.cache.LoadingCache.getUnchecked.

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 get, 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 get or getUnchecked 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 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 get instead.

Annotations
@Override
@SuppressWarnings:CatchingUnchecked, NullAway, PMD.AvoidCatchingNPE, PMD.PreserveStackTrace
refreshback to summary
public void refresh(K key)

Implements com.google.common.cache.LoadingCache.refresh.

Doc from com.google.common.cache.LoadingCache.refresh.

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 java.util.logging.Logger) and swallowed.

Caches loaded by a CacheLoader will call CacheLoader#reload if the cache currently contains a value for key, and CacheLoader#load otherwise. Loading is asynchronous only if CacheLoader#reload 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.

Annotations
@Override
@SuppressWarnings:FutureReturnValueIgnored
com.github.benmanes.caffeine.guava back to summary

pack-priv abstract Class CaffeinatedGuavaLoadingCache.CaffeinatedLoader<K, V>

extends Object
implements CacheLoader<K, V>, Serializable
Class Inheritance
  • java.lang.Object
  • com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader
All Implemented Interfaces
java.io.Serializable, com.github.benmanes.caffeine.cache.CacheLoader, com.github.benmanes.caffeine.cache.AsyncCacheLoader
Known Direct Subclasses
com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.InternalSingleLoader, com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.ExternalSingleLoader

Field Summary

Modifier and TypeField and Description
pack-priv final CacheLoader<K, V>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
CaffeinatedLoader(CacheLoader<K, V> cacheLoader)

Method Summary

Modifier and TypeMethod and Description
public CompletableFuture<V>
asyncReload(K
the non-null key whose value should be loaded
key
,
V
the non-null old value corresponding to key
oldValue
,
Executor
the executor with which the entry is asynchronously loaded
executor
)

Overrides default com.github.benmanes.caffeine.cache.CacheLoader.asyncReload.

Asynchronously computes or retrieves a replacement value corresponding to an already-cached key.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheLoaderback to summary
pack-priv final CacheLoader<K, V> cacheLoader
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

CaffeinatedLoaderback to summary
pack-priv CaffeinatedLoader(CacheLoader<K, V> cacheLoader)

Method Detail

asyncReloadback to summary
public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor)

Overrides default com.github.benmanes.caffeine.cache.CacheLoader.asyncReload.

Doc from com.github.benmanes.caffeine.cache.CacheLoader.asyncReload.

Asynchronously computes or retrieves a replacement value corresponding to an already-cached key. If the replacement value is not found then the mapping will be removed if null is computed. This method is called when an existing cache entry is refreshed by Caffeine#refreshAfterWrite, or through a call to LoadingCache#refresh.

Warning

loading must not attempt to update any mappings of this cache directly or block waiting for other cache operations to complete.

Note

all exceptions thrown by this method will be logged and then swallowed.

Parameters
key:K

the non-null key whose value should be loaded

oldValue:V

the non-null old value corresponding to key

executor:Executor

the executor with which the entry is asynchronously loaded

Returns:CompletableFuture<V>

a future containing the new value associated with key, or containing null if the mapping is to be removed

Annotations
@Override
com.github.benmanes.caffeine.guava back to summary

pack-priv final Class CaffeinatedGuavaLoadingCache.ExternalBulkLoader<K, V>

extends CaffeinatedGuavaLoadingCache.ExternalSingleLoader<K, V>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
ExternalBulkLoader(CacheLoader<K, V> cacheLoader)

Method Summary

Modifier and TypeMethod and Description
public Map<K, V>
loadAll(Set<? extends K>
the unique, non-null keys whose values should be loaded
keys
)

Overrides default com.github.benmanes.caffeine.cache.CacheLoader.loadAll.

Computes or retrieves the values corresponding to keys.
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.ExternalSingleLoader:
load

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.ExternalSingleLoader.serialVersionUID.

Constructor Detail

ExternalBulkLoaderback to summary
pack-priv ExternalBulkLoader(CacheLoader<K, V> cacheLoader)

Method Detail

loadAllback to summary
public Map<K, V> loadAll(Set<? extends K> keys) throws Exception

Overrides default com.github.benmanes.caffeine.cache.CacheLoader.loadAll.

Doc from com.github.benmanes.caffeine.cache.CacheLoader.loadAll.

Computes or retrieves the values corresponding to keys. This method is called by LoadingCache#getAll.

If the returned map doesn't contain all requested keys, then the entries it does contain will be cached, and getAll will return the partial results. If the returned map contains extra keys not present in keys then all returned entries will be cached, but only the entries for keys, will be returned from getAll.

This method should be overridden when bulk retrieval is significantly more efficient than many individual lookups. Note that LoadingCache#getAll will defer to individual calls to LoadingCache#get if this method is not overridden.

Warning

loading must not attempt to update any mappings of this cache directly.

Parameters
keys:Set<? extends K>

the unique, non-null keys whose values should be loaded

Returns:Map<K, V>

a map from each key in keys to the value associated with that key; may not contain null values

Annotations
@Override
Exceptions
Exception:
or Error, in which case the mappings are unchanged
com.github.benmanes.caffeine.guava back to summary

pack-priv Class CaffeinatedGuavaLoadingCache.ExternalSingleLoader<K, V>

extends CaffeinatedGuavaLoadingCache.CaffeinatedLoader<K, V>
Class Inheritance
Known Direct Subclasses
com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.ExternalBulkLoader

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader:
cacheLoader

Constructor Summary

AccessConstructor and Description
pack-priv
ExternalSingleLoader(CacheLoader<K, V> cacheLoader)

Method Summary

Modifier and TypeMethod and Description
public V
load(K
the non-null key whose value should be loaded
key
)

Implements com.github.benmanes.caffeine.cache.CacheLoader.load.

Computes or retrieves the value corresponding to key.
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader:
asyncReload

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader.serialVersionUID.

Constructor Detail

ExternalSingleLoaderback to summary
pack-priv ExternalSingleLoader(CacheLoader<K, V> cacheLoader)

Method Detail

loadback to summary
public V load(K key) throws Exception

Implements com.github.benmanes.caffeine.cache.CacheLoader.load.

Doc from com.github.benmanes.caffeine.cache.CacheLoader.load.

Computes or retrieves the value corresponding to key.

Warning

loading must not attempt to update any mappings of this cache directly.

Parameters
key:K

the non-null key whose value should be loaded

Returns:V

the value associated with key or null if not found

Annotations
@Override
Exceptions
Exception:
or Error, in which case the mapping is unchanged
com.github.benmanes.caffeine.guava back to summary

pack-priv final Class CaffeinatedGuavaLoadingCache.FutureCompleter<V>

extends Object
implements FutureCallback<V>
Class Inheritance
  • java.lang.Object
  • com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.FutureCompleter
All Implemented Interfaces
com.google.common.util.concurrent.FutureCallback

Field Summary

Modifier and TypeField and Description
pack-priv final CompletableFuture<V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
onFailure(Throwable t)

Implements com.google.common.util.concurrent.FutureCallback.onFailure.

Invoked when a Future computation fails or is canceled.
public void
onSuccess(@Nullable V value)

Implements com.google.common.util.concurrent.FutureCallback.onSuccess.

Invoked with the result of the Future computation when it is successful.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

futureback to summary
pack-priv final CompletableFuture<V> future

Constructor Detail

FutureCompleterback to summary
pack-priv FutureCompleter(CompletableFuture<V> future)

Method Detail

onFailureback to summary
public void onFailure(Throwable t)

Implements com.google.common.util.concurrent.FutureCallback.onFailure.

Doc from com.google.common.util.concurrent.FutureCallback.onFailure.

Invoked when a Future computation fails or is canceled.

If the future's get method throws an ExecutionException, then the cause is passed to this method. Any other thrown object is passed unaltered.

Annotations
@Override
onSuccessback to summary
public void onSuccess(@Nullable V value)

Implements com.google.common.util.concurrent.FutureCallback.onSuccess.

Doc from com.google.common.util.concurrent.FutureCallback.onSuccess.

Invoked with the result of the Future computation when it is successful.

Annotations
@Override
com.github.benmanes.caffeine.guava back to summary

pack-priv final Class CaffeinatedGuavaLoadingCache.InternalBulkLoader<K, V>

extends CaffeinatedGuavaLoadingCache.InternalSingleLoader<K, V>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
InternalBulkLoader(CacheLoader<K, V> cacheLoader)

Method Summary

Modifier and TypeMethod and Description
public Map<K, V>
loadAll(Set<? extends K>
the unique, non-null keys whose values should be loaded
keys
)

Overrides default com.github.benmanes.caffeine.cache.CacheLoader.loadAll.

Computes or retrieves the values corresponding to keys.
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.InternalSingleLoader:
load

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.InternalSingleLoader.serialVersionUID.

Constructor Detail

InternalBulkLoaderback to summary
pack-priv InternalBulkLoader(CacheLoader<K, V> cacheLoader)

Method Detail

loadAllback to summary
public Map<K, V> loadAll(Set<? extends K> keys)

Overrides default com.github.benmanes.caffeine.cache.CacheLoader.loadAll.

Doc from com.github.benmanes.caffeine.cache.CacheLoader.loadAll.

Computes or retrieves the values corresponding to keys. This method is called by LoadingCache#getAll.

If the returned map doesn't contain all requested keys, then the entries it does contain will be cached, and getAll will return the partial results. If the returned map contains extra keys not present in keys then all returned entries will be cached, but only the entries for keys, will be returned from getAll.

This method should be overridden when bulk retrieval is significantly more efficient than many individual lookups. Note that LoadingCache#getAll will defer to individual calls to LoadingCache#get if this method is not overridden.

Warning

loading must not attempt to update any mappings of this cache directly.

Parameters
keys:Set<? extends K>

the unique, non-null keys whose values should be loaded

Returns:Map<K, V>

a map from each key in keys to the value associated with that key; may not contain null values

Annotations
@Override
com.github.benmanes.caffeine.guava back to summary

pack-priv Class CaffeinatedGuavaLoadingCache.InternalSingleLoader<K, V>

extends CaffeinatedGuavaLoadingCache.CaffeinatedLoader<K, V>
Class Inheritance
Known Direct Subclasses
com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.InternalBulkLoader

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader:
cacheLoader

Constructor Summary

AccessConstructor and Description
pack-priv
InternalSingleLoader(CacheLoader<K, V> cacheLoader)

Method Summary

Modifier and TypeMethod and Description
public V
load(K
the non-null key whose value should be loaded
key
)

Implements com.github.benmanes.caffeine.cache.CacheLoader.load.

Computes or retrieves the value corresponding to key.
Inherited from com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader:
asyncReload

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.CaffeinatedLoader.serialVersionUID.

Constructor Detail

InternalSingleLoaderback to summary
pack-priv InternalSingleLoader(CacheLoader<K, V> cacheLoader)

Method Detail

loadback to summary
public V load(K key)

Implements com.github.benmanes.caffeine.cache.CacheLoader.load.

Doc from com.github.benmanes.caffeine.cache.CacheLoader.load.

Computes or retrieves the value corresponding to key.

Warning

loading must not attempt to update any mappings of this cache directly.

Parameters
key:K

the non-null key whose value should be loaded

Returns:V

the value associated with key or null if not found

Annotations
@Override