Top Description Methods
com.github.benmanes.caffeine.cache

pack-priv Interface LocalCache<K, V>

extends ConcurrentMap<K, V>
Known Direct Implementers
com.github.benmanes.caffeine.cache.UnboundedLocalCache, com.github.benmanes.caffeine.cache.BoundedLocalCache
Imports
java.util.Map, java.util.concurrent.CompletableFuture, .ConcurrentMap, .Executor, java.util.function.BiFunction, .Function, org.checkerframework.checker.nullness.qual.Nullable, com.github.benmanes.caffeine.cache.stats.StatsCounter

An in-memory cache providing thread safety and atomicity guarantees. This interface provides an extension to ConcurrentMap for use with skeletal implementations.
Author
[email protected] (Ben Manes)

Method Summary

Modifier and TypeMethod and Description
public void
public default @Nullable V
compute(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super V, ? extends V>
the remapping function to compute a value
remappingFunction
)

Overrides default java.util.concurrent.ConcurrentMap.compute.

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
public @Nullable V
compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, @Nullable Expiry<? super K, ? super V> expiry, boolean recordLoad, boolean recordLoadFailure)

See ConcurrentMap#compute.

public default @Nullable V
computeIfAbsent(K
key with which the specified value is to be associated
key
,
Function<? super K, ? extends V>
the mapping function to compute a value
mappingFunction
)

Overrides default java.util.concurrent.ConcurrentMap.computeIfAbsent.

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
public @Nullable V
computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, boolean recordStats, boolean recordLoad)

See ConcurrentMap#computeIfAbsent.

public long
public Executor
executor()

Returns the Executor used by this cache.

public @Nullable Expiry<K, V>
expiry()

Returns the Expiry used by this cache.

public Map<K, V>
public @Nullable V
getIfPresent(K key, boolean recordStats)

See Cache#getIfPresent(K).

public @Nullable V
public default void
public boolean
isAsync()

Returns whether this cache is asynchronous.

public boolean
isPendingEviction(K key)

Returns whether an absent entry has expired or has been reference collected but has not yet been removed from the cache.

public boolean
isRecordingStats()

Returns whether this cache has statistics enabled.

public default void
notifyOnReplace(K key, V oldValue, V newValue)

Notify the removal listener of a replacement if the value reference was changed.

public void
notifyRemoval(@Nullable K key, @Nullable V value, RemovalCause cause)

Asynchronously sends a removal notification to the listener.

public Object
referenceKey(K key)

Returns the reference key.

public ConcurrentMap<Object, CompletableFuture<?>>
refreshes()

Returns the map of in-flight refresh operations.

public boolean
replace(K key, V oldValue, V newValue, boolean shouldDiscardRefresh)

See ConcurrentMap#replace(K, K, V).

public default <T, R> Function<? super T, ? extends R>
statsAware(Function<? super T, ? extends R> mappingFunction, boolean recordLoad)

Decorates the remapping function to record statistics if enabled.

public default <T, U, R> BiFunction<? super T, ? super U, ? extends R>
statsAware(BiFunction<? super T, ? super U, ? extends R> remappingFunction)

Decorates the remapping function to record statistics if enabled.

public default <T, U, R> BiFunction<? super T, ? super U, ? extends R>
statsAware(BiFunction<? super T, ? super U, ? extends R> remappingFunction, boolean recordLoad, boolean recordLoadFailure)

Decorates the remapping function to record statistics if enabled.

public StatsCounter
statsCounter()

Returns the StatsCounter used by this cache.

public Ticker
statsTicker()

Returns the Ticker used by this cache for statistics.

Inherited from java.util.concurrent.ConcurrentMap:
computeIfPresentforEachgetOrDefaultmergeputIfAbsentremovereplacereplacereplaceAll

Method Detail

cleanUpback to summary
public void cleanUp()

See Cache#cleanUp.

computeback to summary
public default @Nullable V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

Overrides default java.util.concurrent.ConcurrentMap.compute.

Doc from java.util.concurrent.ConcurrentMap.compute.

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). For example, to either create or append a String msg to a value mapping:

 map.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))
(Method merge() is often simpler to use for such purposes.)

If the remapping function returns null, the mapping is removed (or remains absent if initially absent). If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

The remapping function should not modify this map during computation.

Parameters
key:K

Doc from java.util.Map.compute.

key with which the specified value is to be associated

remappingFunction:BiFunction<? super K, ? super V, ? extends V>

Doc from java.util.Map.compute.

the remapping function to compute a value

Returns:@Nullable V

Doc from java.util.Map.compute.

the new value associated with the specified key, or null if none

Annotations
@Override
computeback to summary
public @Nullable V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, @Nullable Expiry<? super K, ? super V> expiry, boolean recordLoad, boolean recordLoadFailure)

See ConcurrentMap#compute. This method differs by accepting parameters indicating whether to record load statistics based on the success of this operation.

computeIfAbsentback to summary
public default @Nullable V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)

Overrides default java.util.concurrent.ConcurrentMap.computeIfAbsent.

Doc from java.util.concurrent.ConcurrentMap.computeIfAbsent.

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.

If the mapping function returns null, no mapping is recorded. If the mapping function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded. The most common usage is to construct a new object serving as an initial mapped value or memoized result, as in:

 map.computeIfAbsent(key, k -> new Value(f(k)));

Or to implement a multi-value map, Map<K,Collection<V>>, supporting multiple values per key:

 map.computeIfAbsent(key, k -> new HashSet<V>()).add(v);

The mapping function should not modify this map during computation.

Parameters
key:K

Doc from java.util.Map.computeIfAbsent.

key with which the specified value is to be associated

mappingFunction:Function<? super K, ? extends V>

Doc from java.util.Map.computeIfAbsent.

the mapping function to compute a value

Returns:@Nullable V

Doc from java.util.Map.computeIfAbsent.

the current (existing or computed) value associated with the specified key, or null if the computed value is null

Annotations
@Override
computeIfAbsentback to summary
public @Nullable V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, boolean recordStats, boolean recordLoad)

See ConcurrentMap#computeIfAbsent. This method differs by accepting parameters indicating how to record statistics.

estimatedSizeback to summary
public long estimatedSize()

See Cache#estimatedSize().

executorback to summary
public Executor executor()

Returns the Executor used by this cache.

expiryback to summary
public @Nullable Expiry<K, V> expiry()

Returns the Expiry used by this cache.

getAllPresentback to summary
public Map<K, V> getAllPresent(Iterable<? extends K> keys)

See Cache#getAllPresent.

getIfPresentback to summary
public @Nullable V getIfPresent(K key, boolean recordStats)

See Cache#getIfPresent(K). This method differs by accepting a parameter of whether to record the hit-and-miss statistics based on the success of this operation.

getIfPresentQuietlyback to summary
public @Nullable V getIfPresentQuietly(K key)

See Cache#getIfPresent(K). This method differs by not recording the access with the statistics nor the eviction policy.

invalidateAllback to summary
public default void invalidateAll(Iterable<?> keys)

See Cache#invalidateAll(Iterable).

isAsyncback to summary
public boolean isAsync()

Returns whether this cache is asynchronous.

isPendingEvictionback to summary
public boolean isPendingEviction(K key)

Returns whether an absent entry has expired or has been reference collected but has not yet been removed from the cache.

isRecordingStatsback to summary
public boolean isRecordingStats()

Returns whether this cache has statistics enabled.

notifyOnReplaceback to summary
public default void notifyOnReplace(K key, V oldValue, V newValue)

Notify the removal listener of a replacement if the value reference was changed.

Annotations
@SuppressWarnings:FutureReturnValueIgnored
notifyRemovalback to summary
public void notifyRemoval(@Nullable K key, @Nullable V value, RemovalCause cause)

Asynchronously sends a removal notification to the listener.

referenceKeyback to summary
public Object referenceKey(K key)

Returns the reference key.

refreshesback to summary
public ConcurrentMap<Object, CompletableFuture<?>> refreshes()

Returns the map of in-flight refresh operations.

replaceback to summary
public boolean replace(K key, V oldValue, V newValue, boolean shouldDiscardRefresh)

See ConcurrentMap#replace(K, K, V). This method differs by optionally not discarding an in-flight refresh for the entry if replaced.

statsAwareback to summary
public default <T, R> Function<? super T, ? extends R> statsAware(Function<? super T, ? extends R> mappingFunction, boolean recordLoad)

Decorates the remapping function to record statistics if enabled.

statsAwareback to summary
public default <T, U, R> BiFunction<? super T, ? super U, ? extends R> statsAware(BiFunction<? super T, ? super U, ? extends R> remappingFunction)

Decorates the remapping function to record statistics if enabled.

statsAwareback to summary
public default <T, U, R> BiFunction<? super T, ? super U, ? extends R> statsAware(BiFunction<? super T, ? super U, ? extends R> remappingFunction, boolean recordLoad, boolean recordLoadFailure)

Decorates the remapping function to record statistics if enabled.

statsCounterback to summary
public StatsCounter statsCounter()

Returns the StatsCounter used by this cache.

statsTickerback to summary
public Ticker statsTicker()

Returns the Ticker used by this cache for statistics.