Package org.apache.maven.impl.cache
Interface Cache<K,V>
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of cached values
- All Known Implementing Classes:
Cache.RefConcurrentMap
public interface Cache<K,V>
A cache interface that provides configurable reference types for both keys and values,
and supports automatic cleanup of garbage-collected entries.
This cache is designed for scenarios where:
- Values should be eligible for garbage collection when memory is low
- Concurrent access is required
- Automatic cleanup of stale entries is desired
The cache can use different reference types (none, soft, weak, hard) for both keys and values, depending on the factory method used to create the cache instance.
Note: All implementations are thread-safe and optimized for concurrent read access.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface for listening to cache eviction events.static classA concurrent map implementation that uses configurable reference types for both keys and values, and supports automatic cleanup of garbage-collected entries.static enumEnumeration of reference types that can be used for individual entries. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()default VcomputeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, Cache.ReferenceType referenceType) Computes a value for the given key if it's not already present, using the specified reference type.default booleancontainsKey(K key) static <K,V> Cache <K, V> newCache(Cache.ReferenceType referenceType) static <K,V> Cache <K, V> newCache(Cache.ReferenceType referenceType, String name) static <K,V> Cache <K, V> newCache(Cache.ReferenceType keyReferenceType, Cache.ReferenceType valueReferenceType) Creates a new cache with separate reference types for keys and values.static <K,V> Cache <K, V> newCache(Cache.ReferenceType keyReferenceType, Cache.ReferenceType valueReferenceType, String name) voidremoveIf(BiPredicate<K, V> o) intsize()
-
Method Details
-
computeIfAbsent
V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, Cache.ReferenceType referenceType) Computes a value for the given key if it's not already present, using the specified reference type.This method allows fine-grained control over the reference type used for individual entries, overriding the cache's default reference type for this specific key-value pair.
- Parameters:
key- the key whose associated value is to be returned or computedmappingFunction- the function to compute a valuereferenceType- the reference type to use for this entry (null uses cache default)- Returns:
- the current (existing or computed) value associated with the specified key
-
computeIfAbsent
-
removeIf
-
get
-
size
int size() -
clear
void clear() -
containsKey
-
newCache
-
newCache
-
newCache
static <K,V> Cache<K,V> newCache(Cache.ReferenceType keyReferenceType, Cache.ReferenceType valueReferenceType) Creates a new cache with separate reference types for keys and values. This allows fine-grained control over eviction behavior and enables better tracking of cache misses caused by key vs value evictions.- Parameters:
keyReferenceType- the reference type to use for keysvalueReferenceType- the reference type to use for values- Returns:
- a new cache instance
-
newCache
static <K,V> Cache<K,V> newCache(Cache.ReferenceType keyReferenceType, Cache.ReferenceType valueReferenceType, String name)
-