Class LocalCache.LoadingSerializationProxy<K,V>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.cache.ForwardingCache<K,V>
-
- com.google.common.cache.LocalCache.ManualSerializationProxy<K,V>
-
- com.google.common.cache.LocalCache.LoadingSerializationProxy<K,V>
-
- All Implemented Interfaces:
Function<K,V>
,Cache<K,V>
,LoadingCache<K,V>
,java.io.Serializable
,java.util.function.Function<K,V>
- Enclosing class:
- LocalCache<K,V>
static final class LocalCache.LoadingSerializationProxy<K,V> extends LocalCache.ManualSerializationProxy<K,V> implements LoadingCache<K,V>, java.io.Serializable
Serializes the configuration of a LocalCache, reconstituting it as an LoadingCache using CacheBuilder upon deserialization. An instance of this class is fit for use by the writeReplace of LocalLoadingCache.Unfortunately, readResolve() doesn't get called when a circular dependency is present, so the proxy must be able to behave as the cache itself.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.cache.ForwardingCache
ForwardingCache.SimpleForwardingCache<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) LoadingCache<K,V>
autoDelegate
private static long
serialVersionUID
-
Fields inherited from class com.google.common.cache.LocalCache.ManualSerializationProxy
concurrencyLevel, delegate, expireAfterAccessNanos, expireAfterWriteNanos, keyEquivalence, keyStrength, loader, maxWeight, removalListener, ticker, valueEquivalence, valueStrength, weigher
-
-
Constructor Summary
Constructors Constructor Description LoadingSerializationProxy(LocalCache<K,V> cache)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description V
apply(K key)
V
get(K key)
Returns the value associated withkey
in this cache, first loading that value if necessary.ImmutableMap<K,V>
getAll(java.lang.Iterable<? extends K> keys)
Returns a map of the values associated withkeys
, creating or retrieving those values if necessary.V
getUnchecked(K key)
Returns the value associated withkey
in this cache, first loading that value if necessary.private void
readObject(java.io.ObjectInputStream in)
private java.lang.Object
readResolve()
void
refresh(K key)
Loads a new value for keykey
, possibly asynchronously.-
Methods inherited from class com.google.common.cache.LocalCache.ManualSerializationProxy
delegate, recreateCacheBuilder
-
Methods inherited from class com.google.common.cache.ForwardingCache
asMap, cleanUp, get, getAllPresent, getIfPresent, invalidate, invalidateAll, invalidateAll, put, putAll, size, stats
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.cache.Cache
cleanUp, get, getAllPresent, getIfPresent, invalidate, invalidateAll, invalidateAll, put, putAll, size, stats
-
Methods inherited from interface com.google.common.cache.LoadingCache
asMap
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
autoDelegate
transient LoadingCache<K,V> autoDelegate
-
-
Constructor Detail
-
LoadingSerializationProxy
LoadingSerializationProxy(LocalCache<K,V> cache)
-
-
Method Detail
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
get
public V get(K key) throws java.util.concurrent.ExecutionException
Description copied from interface:LoadingCache
Returns the value associated withkey
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
LoadingCache.get(K)
orLoadingCache.getUnchecked(K)
is currently loading the value forkey
, 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 callCacheLoader.load(K)
to load new values into the cache. Newly loaded values are added to the cache usingCache.asMap().putIfAbsent
after loading has completed; if another value was associated withkey
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
LoadingCache.getUnchecked(K)
over this method.- Specified by:
get
in interfaceLoadingCache<K,V>
- Throws:
java.util.concurrent.ExecutionException
- if a checked exception was thrown while loading the value. (ExecutionException
is thrown even if computation was interrupted by anInterruptedException
.)
-
getUnchecked
public V getUnchecked(K key)
Description copied from interface:LoadingCache
Returns the value associated withkey
in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes. UnlikeLoadingCache.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)
orLoadingCache.getUnchecked(K)
is currently loading the value forkey
, 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 callCacheLoader.load(K)
to load new values into the cache. Newly loaded values are added to the cache usingCache.asMap().putIfAbsent
after loading has completed; if another value was associated withkey
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 interfaceLoadingCache<K,V>
-
getAll
public ImmutableMap<K,V> getAll(java.lang.Iterable<? extends K> keys) throws java.util.concurrent.ExecutionException
Description copied from interface:LoadingCache
Returns a map of the values associated withkeys
, 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 toCacheLoader.loadAll(java.lang.Iterable<? extends K>)
for all keys which are not already present in the cache. All entries returned byCacheLoader.loadAll(java.lang.Iterable<? extends K>)
will be stored in the cache, over-writing any previously cached values. This method will throw an exception ifCacheLoader.loadAll(java.lang.Iterable<? extends K>)
returnsnull
, 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 byObject.equals(java.lang.Object)
, will be ignored.- Specified by:
getAll
in interfaceLoadingCache<K,V>
- Throws:
java.util.concurrent.ExecutionException
- if a checked exception was thrown while loading the value. (ExecutionException
is thrown even if computation was interrupted by anInterruptedException
.)
-
refresh
public void refresh(K key)
Description copied from interface:LoadingCache
Loads a new value for keykey
, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned byget(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 (usingLogger
) and swallowed.Caches loaded by a
CacheLoader
will callCacheLoader.reload(K, V)
if the cache currently contains a value forkey
, andCacheLoader.load(K)
otherwise. Loading is asynchronous only ifCacheLoader.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 interfaceLoadingCache<K,V>
-
readResolve
private java.lang.Object readResolve()
-
-