Class UnboundedLocalCache<K,V>
java.lang.Object
com.github.benmanes.caffeine.cache.UnboundedLocalCache<K,V>
- All Implemented Interfaces:
LocalCache<K,
,V> ConcurrentMap<K,
,V> Map<K,
V>
An in-memory cache that has no capabilities for bounding the map. This implementation provides
a lightweight wrapper on top of
ConcurrentHashMap
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
An adapter to safely externalize the entry iterator.(package private) static final class
An adapter to safely externalize the entries.(package private) static final class
An adapter to safely externalize the entry spliterator.(package private) static final class
An adapter to safely externalize the key iterator.(package private) static final class
An adapter to safely externalize the keys.(package private) static final class
(package private) static final class
(package private) static final class
(package private) static class
(package private) static final class
An eviction policy that supports no boundings.(package private) static final class
An adapter to safely externalize the value iterator.(package private) static final class
An adapter to safely externalize the values. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ConcurrentHashMap
<K, V> (package private) final Executor
(package private) final boolean
(package private) final @Nullable RemovalListener
<K, V> (package private) final StatsCounter
(package private) final Ticker
(package private) @Nullable Collection
<V> (package private) final CacheWriter
<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanUp()
SeeCache.cleanUp()
.void
clear()
compute
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, boolean recordMiss, boolean recordLoad, boolean recordLoadFailure) computeIfAbsent
(K key, Function<? super K, ? extends V> mappingFunction, boolean recordStats, boolean recordLoad) @Nullable V
computeIfPresent
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
boolean
long
executor()
Returns theExecutor
used by this cache.Returns theTicker
used by this cache for expiration.void
forEach
(BiConsumer<? super K, ? super V> action) @Nullable V
getAllPresent
(Iterable<?> keys) @Nullable V
getIfPresent
(Object key, boolean recordStats) @Nullable V
getIfPresentQuietly
(Object key, long[] writeTime) int
hashCode()
boolean
Returns whether this cache notifies when an entry is removed.boolean
Returns whether the cache captures the write time of the entry.boolean
isEmpty()
boolean
Returns whether this cache has statistics enabled.keySet()
void
notifyRemoval
(@Nullable K key, @Nullable V value, RemovalCause cause) Asynchronously sends a removal notification to the listener.@Nullable V
@Nullable V
void
@Nullable V
putIfAbsent
(K key, V value) (package private) V
AMap.compute(Object, BiFunction)
that does not directly record any cache statistics.Returns theRemovalListener
used by this cache.@Nullable V
boolean
@Nullable V
boolean
void
replaceAll
(BiFunction<? super K, ? super V, ? extends V> function) int
size()
Returns theStatsCounter
used by this cache.Returns theTicker
used by this cache for statistics.toString()
values()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.concurrent.ConcurrentMap
getOrDefault
Methods inherited from interface com.github.benmanes.caffeine.cache.LocalCache
compute, computeIfAbsent, invalidateAll, statsAware, statsAware, statsAware
-
Field Details
-
removalListener
-
data
-
statsCounter
-
isRecordingStats
final boolean isRecordingStats -
writer
-
executor
-
ticker
-
keySet
-
values
-
entrySet
-
-
Constructor Details
-
UnboundedLocalCache
-
-
Method Details
-
hasWriteTime
public boolean hasWriteTime()Description copied from interface:LocalCache
Returns whether the cache captures the write time of the entry.- Specified by:
hasWriteTime
in interfaceLocalCache<K,
V>
-
getIfPresent
Description copied from interface:LocalCache
SeeCache.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:
getIfPresent
in interfaceLocalCache<K,
V>
-
getIfPresentQuietly
Description copied from interface:LocalCache
SeeCache.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:
getIfPresentQuietly
in interfaceLocalCache<K,
V>
-
estimatedSize
public long estimatedSize()Description copied from interface:LocalCache
- Specified by:
estimatedSize
in interfaceLocalCache<K,
V>
-
getAllPresent
Description copied from interface:LocalCache
- Specified by:
getAllPresent
in interfaceLocalCache<K,
V>
-
cleanUp
public void cleanUp()Description copied from interface:LocalCache
SeeCache.cleanUp()
.- Specified by:
cleanUp
in interfaceLocalCache<K,
V>
-
statsCounter
Description copied from interface:LocalCache
Returns theStatsCounter
used by this cache.- Specified by:
statsCounter
in interfaceLocalCache<K,
V>
-
hasRemovalListener
public boolean hasRemovalListener()Description copied from interface:LocalCache
Returns whether this cache notifies when an entry is removed.- Specified by:
hasRemovalListener
in interfaceLocalCache<K,
V>
-
removalListener
Description copied from interface:LocalCache
Returns theRemovalListener
used by this cache.- Specified by:
removalListener
in interfaceLocalCache<K,
V>
-
notifyRemoval
Description copied from interface:LocalCache
Asynchronously sends a removal notification to the listener.- Specified by:
notifyRemoval
in interfaceLocalCache<K,
V>
-
isRecordingStats
public boolean isRecordingStats()Description copied from interface:LocalCache
Returns whether this cache has statistics enabled.- Specified by:
isRecordingStats
in interfaceLocalCache<K,
V>
-
executor
Description copied from interface:LocalCache
Returns theExecutor
used by this cache.- Specified by:
executor
in interfaceLocalCache<K,
V>
-
expirationTicker
Description copied from interface:LocalCache
Returns theTicker
used by this cache for expiration.- Specified by:
expirationTicker
in interfaceLocalCache<K,
V>
-
statsTicker
Description copied from interface:LocalCache
Returns theTicker
used by this cache for statistics.- Specified by:
statsTicker
in interfaceLocalCache<K,
V>
-
forEach
-
replaceAll
- Specified by:
replaceAll
in interfaceConcurrentMap<K,
V> - Specified by:
replaceAll
in interfaceMap<K,
V>
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, boolean recordStats, boolean recordLoad) Description copied from interface:LocalCache
SeeConcurrentMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
. This method differs by accepting parameters indicating how to record statistics.- Specified by:
computeIfAbsent
in interfaceLocalCache<K,
V>
-
computeIfPresent
public @Nullable V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) - Specified by:
computeIfPresent
in interfaceConcurrentMap<K,
V> - Specified by:
computeIfPresent
in interfaceMap<K,
V>
-
compute
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, boolean recordMiss, boolean recordLoad, boolean recordLoadFailure) Description copied from interface:LocalCache
SeeConcurrentMap.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:
compute
in interfaceLocalCache<K,
V>
-
merge
-
remap
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
-
isEmpty
public boolean isEmpty() -
size
public int size() -
clear
public void clear() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
put
Description copied from interface:LocalCache
SeeCache.put(Object, Object)
. This method differs by allowing the operation to not notify the writer when an entry was inserted or updated.- Specified by:
put
in interfaceLocalCache<K,
V>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceConcurrentMap<K,
V> - Specified by:
putIfAbsent
in interfaceMap<K,
V>
-
putAll
-
remove
-
remove
-
replace
-
replace
-
equals
-
hashCode
public int hashCode() -
toString
-
keySet
-
values
-
entrySet
-