Class UnboundedLocalCache<K,V>
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.UnboundedLocalCache<K,V>
-
- All Implemented Interfaces:
LocalCache<K,V>,java.util.concurrent.ConcurrentMap<K,V>,java.util.Map<K,V>
final class UnboundedLocalCache<K,V> extends java.lang.Object implements LocalCache<K,V>
An in-memory cache that has no capabilities for bounding the map. This implementation provides a lightweight wrapper on top ofConcurrentHashMap.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classUnboundedLocalCache.EntryIterator<K,V>An adapter to safely externalize the entry iterator.(package private) static classUnboundedLocalCache.EntrySetView<K,V>An adapter to safely externalize the entries.(package private) static classUnboundedLocalCache.EntrySpliterator<K,V>An adapter to safely externalize the entry spliterator.(package private) static classUnboundedLocalCache.KeyIterator<K>An adapter to safely externalize the key iterator.(package private) static classUnboundedLocalCache.KeySetView<K>An adapter to safely externalize the keys.(package private) static classUnboundedLocalCache.UnboundedLocalAsyncCache<K,V>(package private) static classUnboundedLocalCache.UnboundedLocalAsyncLoadingCache<K,V>(package private) static classUnboundedLocalCache.UnboundedLocalLoadingCache<K,V>(package private) static classUnboundedLocalCache.UnboundedLocalManualCache<K,V>(package private) static classUnboundedLocalCache.UnboundedPolicy<K,V>An eviction policy that supports no boundings.(package private) static classUnboundedLocalCache.ValuesIterator<K,V>An adapter to safely externalize the value iterator.(package private) static classUnboundedLocalCache.ValuesView<K,V>An adapter to safely externalize the values.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.ConcurrentHashMap<K,V>data(package private) @Nullable java.util.Set<java.util.Map.Entry<K,V>>entrySet(package private) java.util.concurrent.Executorexecutor(package private) booleanisRecordingStats(package private) @Nullable java.util.Set<K>keySet(package private) @Nullable RemovalListener<K,V>removalListener(package private) StatsCounterstatsCounter(package private) Tickerticker(package private) @Nullable java.util.Collection<V>values(package private) CacheWriter<K,V>writer
-
Constructor Summary
Constructors Constructor Description UnboundedLocalCache(Caffeine<? super K,? super V> builder, boolean async)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanUp()SeeCache.cleanUp().voidclear()Vcompute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, boolean recordMiss, boolean recordLoad, boolean recordLoadFailure)SeeConcurrentMap.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>).VcomputeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction, boolean recordStats, boolean recordLoad)SeeConcurrentMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>).@Nullable VcomputeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object o)longestimatedSize()java.util.concurrent.Executorexecutor()Returns theExecutorused by this cache.TickerexpirationTicker()Returns theTickerused by this cache for expiration.voidforEach(java.util.function.BiConsumer<? super K,? super V> action)@Nullable Vget(java.lang.Object key)java.util.Map<K,V>getAllPresent(java.lang.Iterable<?> keys)@Nullable VgetIfPresent(java.lang.Object key, boolean recordStats)@Nullable VgetIfPresentQuietly(java.lang.Object key, long[] writeTime)inthashCode()booleanhasRemovalListener()Returns whether this cache notifies when an entry is removed.booleanhasWriteTime()Returns whether the cache captures the write time of the entry.booleanisEmpty()booleanisRecordingStats()Returns whether this cache has statistics enabled.java.util.Set<K>keySet()Vmerge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)voidnotifyRemoval(@Nullable K key, @Nullable V value, RemovalCause cause)Asynchronously sends a removal notification to the listener.@Nullable Vput(K key, V value)@Nullable Vput(K key, V value, boolean notifyWriter)voidputAll(java.util.Map<? extends K,? extends V> map)@Nullable VputIfAbsent(K key, V value)(package private) Vremap(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)AMap.compute(Object, BiFunction)that does not directly record any cache statistics.RemovalListener<K,V>removalListener()Returns theRemovalListenerused by this cache.@Nullable Vremove(java.lang.Object key)booleanremove(java.lang.Object key, java.lang.Object value)@Nullable Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)voidreplaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)intsize()StatsCounterstatsCounter()Returns theStatsCounterused by this cache.TickerstatsTicker()Returns theTickerused by this cache for statistics.java.lang.StringtoString()java.util.Collection<V>values()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.benmanes.caffeine.cache.LocalCache
compute, computeIfAbsent, invalidateAll, statsAware, statsAware, statsAware
-
-
-
-
Field Detail
-
removalListener
final @Nullable RemovalListener<K,V> removalListener
-
statsCounter
final StatsCounter statsCounter
-
isRecordingStats
final boolean isRecordingStats
-
writer
final CacheWriter<K,V> writer
-
executor
final java.util.concurrent.Executor executor
-
ticker
final Ticker ticker
-
keySet
transient @Nullable java.util.Set<K> keySet
-
values
transient @Nullable java.util.Collection<V> values
-
-
Method Detail
-
hasWriteTime
public boolean hasWriteTime()
Description copied from interface:LocalCacheReturns whether the cache captures the write time of the entry.- Specified by:
hasWriteTimein interfaceLocalCache<K,V>
-
getIfPresent
public @Nullable V getIfPresent(java.lang.Object key, boolean recordStats)
Description copied from interface:LocalCacheSeeCache.getIfPresent(Object). This method differs by accepting a parameter of whether to record the hit and miss statistics based on the success of this operation.- Specified by:
getIfPresentin interfaceLocalCache<K,V>
-
getIfPresentQuietly
public @Nullable V getIfPresentQuietly(java.lang.Object key, long[] writeTime)
Description copied from interface:LocalCacheSeeCache.getIfPresent(Object). This method differs by not recording the access with the statistics nor the eviction policy, and populates the write time if known.- Specified by:
getIfPresentQuietlyin interfaceLocalCache<K,V>
-
estimatedSize
public long estimatedSize()
Description copied from interface:LocalCache- Specified by:
estimatedSizein interfaceLocalCache<K,V>
-
getAllPresent
public java.util.Map<K,V> getAllPresent(java.lang.Iterable<?> keys)
Description copied from interface:LocalCache- Specified by:
getAllPresentin interfaceLocalCache<K,V>
-
cleanUp
public void cleanUp()
Description copied from interface:LocalCacheSeeCache.cleanUp().- Specified by:
cleanUpin interfaceLocalCache<K,V>
-
statsCounter
public StatsCounter statsCounter()
Description copied from interface:LocalCacheReturns theStatsCounterused by this cache.- Specified by:
statsCounterin interfaceLocalCache<K,V>
-
hasRemovalListener
public boolean hasRemovalListener()
Description copied from interface:LocalCacheReturns whether this cache notifies when an entry is removed.- Specified by:
hasRemovalListenerin interfaceLocalCache<K,V>
-
removalListener
public RemovalListener<K,V> removalListener()
Description copied from interface:LocalCacheReturns theRemovalListenerused by this cache.- Specified by:
removalListenerin interfaceLocalCache<K,V>
-
notifyRemoval
public void notifyRemoval(@Nullable K key, @Nullable V value, RemovalCause cause)
Description copied from interface:LocalCacheAsynchronously sends a removal notification to the listener.- Specified by:
notifyRemovalin interfaceLocalCache<K,V>
-
isRecordingStats
public boolean isRecordingStats()
Description copied from interface:LocalCacheReturns whether this cache has statistics enabled.- Specified by:
isRecordingStatsin interfaceLocalCache<K,V>
-
executor
public java.util.concurrent.Executor executor()
Description copied from interface:LocalCacheReturns theExecutorused by this cache.- Specified by:
executorin interfaceLocalCache<K,V>
-
expirationTicker
public Ticker expirationTicker()
Description copied from interface:LocalCacheReturns theTickerused by this cache for expiration.- Specified by:
expirationTickerin interfaceLocalCache<K,V>
-
statsTicker
public Ticker statsTicker()
Description copied from interface:LocalCacheReturns theTickerused by this cache for statistics.- Specified by:
statsTickerin interfaceLocalCache<K,V>
-
replaceAll
public void replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
-
computeIfAbsent
public V computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction, boolean recordStats, boolean recordLoad)
Description copied from interface:LocalCacheSeeConcurrentMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>). This method differs by accepting parameters indicating how to record statistics.- Specified by:
computeIfAbsentin interfaceLocalCache<K,V>
-
computeIfPresent
public @Nullable V computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
-
compute
public V compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, boolean recordMiss, boolean recordLoad, boolean recordLoadFailure)
Description copied from interface:LocalCacheSeeConcurrentMap.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>). This method differs by accepting parameters indicating whether to record miss and load statistics based on the success of this operation.- Specified by:
computein interfaceLocalCache<K,V>
-
merge
public V merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
-
remap
V remap(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
AMap.compute(Object, BiFunction)that does not directly record any cache statistics.- Parameters:
key- key with which the specified value is to be associatedremappingFunction- the function to compute a value- Returns:
- the new value associated with the specified key, or null if none
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
get
public @Nullable V get(java.lang.Object key)
-
put
public @Nullable V put(K key, V value, boolean notifyWriter)
Description copied from interface:LocalCacheSeeCache.put(Object, Object). This method differs by allowing the operation to not notify the writer when an entry was inserted or updated.- Specified by:
putin interfaceLocalCache<K,V>
-
remove
public @Nullable V remove(java.lang.Object key)
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
values
public java.util.Collection<V> values()
-
-