Class AsyncClaimingCacheImpl<K,V>
java.lang.Object
org.aksw.commons.cache.async.AsyncClaimingCacheImpl<K,V>
- Type Parameters:
K-V-
- All Implemented Interfaces:
AsyncClaimingCache<K,V>
Implementation of async claiming cache.
Claimed entries will never be evicted. Conversely, unclaimed items remain are added to a cache such that timely re-claiming
will be fast.
Use cases:
- Resource sharing: Ensure that the same resource is handed to all clients requesting one by key.
- Resource pooling: Claimed resources will never be closed, but unclaimed resources (e.g. something backed by an input stream)
may remain on standby for a while.
Another way to view this class is as a mix of a map with weak values and a cache.
- Author:
- raven
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BiConsumer<K, RefFuture<V>> protected LinkedList<Predicate<? super K>> protected ReentrantReadWriteLockprotected BiConsumer<K, RefFuture<V>> -
Constructor Summary
ConstructorsConstructorDescriptionAsyncClaimingCacheImpl(Map<K, RefFuture<V>> level1, com.github.benmanes.caffeine.cache.AsyncLoadingCache<K, V> level2, Map<K, V> level3, LinkedList<Predicate<? super K>> evictionGuards, BiConsumer<K, RefFuture<V>> claimListener, BiConsumer<K, RefFuture<V>> unclaimListener, com.github.benmanes.caffeine.cache.RemovalListener<K, V> evictionListener) -
Method Summary
Modifier and TypeMethodDescriptionaddEvictionGuard(Predicate<? super K> predicate) Registers a predicate that 'caches' entries about to be evicted When closing the registration then keys that have not moved back into the ache by reference will be immediately evicted.Claim a reference to the key's entry.claimIfPresent(K key) Claim a key only if it is already present.voidstatic <K,V> AsyncClaimingCacheImpl.Builder <K, V> newBuilder(com.github.benmanes.caffeine.cache.Caffeine<Object, Object> caffeine) protected void
-
Field Details
-
level1
-
level2
-
level3
-
claimListener
-
unclaimListener
-
invalidationLock
-
evictionGuards
-
evictionListener
-
keyToSynchronizer
-
-
Constructor Details
-
AsyncClaimingCacheImpl
public AsyncClaimingCacheImpl(Map<K, RefFuture<V>> level1, com.github.benmanes.caffeine.cache.AsyncLoadingCache<K, V> level2, Map<K, V> level3, LinkedList<Predicate<? super K>> evictionGuards, BiConsumer<K, RefFuture<V>> claimListener, BiConsumer<K, RefFuture<V>> unclaimListener, com.github.benmanes.caffeine.cache.RemovalListener<K, V> evictionListener)
-
-
Method Details
-
addEvictionGuard
Registers a predicate that 'caches' entries about to be evicted When closing the registration then keys that have not moved back into the ache by reference will be immediately evicted.- Specified by:
addEvictionGuardin interfaceAsyncClaimingCache<K,V>
-
runLevel3Eviction
protected void runLevel3Eviction() -
claim
Description copied from interface:AsyncClaimingCacheClaim a reference to the key's entry.- Specified by:
claimin interfaceAsyncClaimingCache<K,V> - Parameters:
key-- Returns:
-
newBuilder
public static <K,V> AsyncClaimingCacheImpl.Builder<K,V> newBuilder(com.github.benmanes.caffeine.cache.Caffeine<Object, Object> caffeine) -
claimIfPresent
Claim a key only if it is already present. This implementation is a best effort approach: There is a very slim chance that just between testing a key for presence and claiming its entry an eviction occurs - causing claiming of a non-present key and thus triggering a load action.- Specified by:
claimIfPresentin interfaceAsyncClaimingCache<K,V>
-
invalidateAll
public void invalidateAll()- Specified by:
invalidateAllin interfaceAsyncClaimingCache<K,V>
-