Interface CacheProvider<K,V>
- Type Parameters:
K- the type of cache keyV- the type of cache entries
- All Known Implementing Classes:
CaffeineCacheProvider
public interface CacheProvider<K,V>
Defines the contract for a cache provider.
- Author:
- Chris Bono
-
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns a view of the entries stored in the cache as a thread-safe map.getOrCreateIfAbsent(K key, Function<K, V> createEntryFunction) Returns the value associated with thekeyin the cache.voidinvalidateAll(BiConsumer<K, V> onInvalidateEntry) Discards all entries in the cache and calls theonInvalidateEntrycallback (if provided) for each entry.
-
Method Details
-
getOrCreateIfAbsent
Returns the value associated with thekeyin the cache.If the key is not already associated with an entry in the cache, the
createEntryFunctionis used to compute the value to cache and return.- Parameters:
key- the cache keycreateEntryFunction- the function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
-
asMap
Returns a view of the entries stored in the cache as a thread-safe map. Modifications made to the map directly affect the cache.- Returns:
- a thread-safe view of the cache supporting all optional
Mapoperations
-
invalidateAll
Discards all entries in the cache and calls theonInvalidateEntrycallback (if provided) for each entry.- Parameters:
onInvalidateEntry- callback invoked for each invalidated entry
-