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 class
UnboundedLocalCache.EntryIterator<K,V>
An adapter to safely externalize the entry iterator.(package private) static class
UnboundedLocalCache.EntrySetView<K,V>
An adapter to safely externalize the entries.(package private) static class
UnboundedLocalCache.EntrySpliterator<K,V>
An adapter to safely externalize the entry spliterator.(package private) static class
UnboundedLocalCache.KeyIterator<K>
An adapter to safely externalize the key iterator.(package private) static class
UnboundedLocalCache.KeySetView<K>
An adapter to safely externalize the keys.(package private) static class
UnboundedLocalCache.UnboundedLocalAsyncLoadingCache<K,V>
(package private) static class
UnboundedLocalCache.UnboundedLocalLoadingCache<K,V>
(package private) static class
UnboundedLocalCache.UnboundedLocalManualCache<K,V>
(package private) static class
UnboundedLocalCache.UnboundedPolicy<K,V>
An eviction policy that supports no boundings.(package private) static class
UnboundedLocalCache.ValuesIterator<K,V>
An adapter to safely externalize the value iterator.(package private) static class
UnboundedLocalCache.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) java.util.Set<java.util.Map.Entry<K,V>>
entrySet
(package private) java.util.concurrent.Executor
executor
(package private) boolean
isRecordingStats
(package private) java.util.Set<K>
keySet
(package private) RemovalListener<K,V>
removalListener
(package private) StatsCounter
statsCounter
(package private) Ticker
ticker
(package private) 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 void
cleanUp()
SeeCache.cleanUp()
.void
clear()
V
compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, boolean recordMiss, boolean recordLoad)
SeeConcurrentMap.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>)
.V
computeIfAbsent(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>)
.V
computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
boolean
equals(java.lang.Object o)
long
estimatedSize()
java.util.concurrent.Executor
executor()
Returns theExecutor
used by this cache.Ticker
expirationTicker()
Returns theTicker
used by this cache for expiration.void
forEach(java.util.function.BiConsumer<? super K,? super V> action)
V
get(java.lang.Object key)
java.util.Map<K,V>
getAllPresent(java.lang.Iterable<?> keys)
V
getIfPresent(java.lang.Object key, boolean recordStats)
V
getIfPresentQuietly(java.lang.Object key, long[] writeTime)
int
hashCode()
boolean
hasRemovalListener()
Returns whether this cache notifies when an entry is removed.boolean
hasWriteTime()
Returns whether the cache captures the write time of the entry.boolean
isEmpty()
boolean
isRecordingStats()
Returns whether this cache has statistics enabled.java.util.Set<K>
keySet()
V
merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
void
notifyRemoval(K key, V value, RemovalCause cause)
Asynchronously sends a removal notification to the listener.V
put(K key, V value)
V
put(K key, V value, boolean notifyWriter)
void
putAll(java.util.Map<? extends K,? extends V> map)
V
putIfAbsent(K key, V value)
(package private) 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.RemovalListener<K,V>
removalListener()
Returns theRemovalListener
used by this cache or null if not used.V
remove(java.lang.Object key)
boolean
remove(java.lang.Object key, java.lang.Object value)
V
replace(K key, V value)
boolean
replace(K key, V oldValue, V newValue)
void
replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
int
size()
StatsCounter
statsCounter()
Returns theStatsCounter
used by this cache.Ticker
statsTicker()
Returns theTicker
used by this cache for statistics.java.lang.String
toString()
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
@Nullable final 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 java.util.Set<K> keySet
-
values
transient java.util.Collection<V> values
-
-
Method Detail
-
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
public V getIfPresent(java.lang.Object key, boolean recordStats)
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
public V getIfPresentQuietly(java.lang.Object key, long[] writeTime)
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
public java.util.Map<K,V> getAllPresent(java.lang.Iterable<?> keys)
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
public StatsCounter 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
public RemovalListener<K,V> removalListener()
Description copied from interface:LocalCache
Returns theRemovalListener
used by this cache or null if not used.- Specified by:
removalListener
in interfaceLocalCache<K,V>
-
notifyRemoval
public void notifyRemoval(@Nullable K key, @Nullable V value, RemovalCause cause)
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
public java.util.concurrent.Executor executor()
Description copied from interface:LocalCache
Returns theExecutor
used by this cache.- Specified by:
executor
in interfaceLocalCache<K,V>
-
expirationTicker
public Ticker expirationTicker()
Description copied from interface:LocalCache
Returns theTicker
used by this cache for expiration.- Specified by:
expirationTicker
in interfaceLocalCache<K,V>
-
statsTicker
public Ticker statsTicker()
Description copied from interface:LocalCache
Returns theTicker
used by this cache for statistics.- Specified by:
statsTicker
in 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: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 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)
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
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)
-
put
public V put(K key, V value, boolean notifyWriter)
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>
-
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:
toString
in classjava.lang.Object
-
values
public java.util.Collection<V> values()
-
-