Class AsyncClaimingCacheImplGuava<K,V>
java.lang.Object
org.apache.jena.sparql.service.enhancer.claimingcache.AsyncClaimingCacheImplGuava<K,V>
- Type Parameters:
K- The key typeV- The value type
- 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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionAsyncClaimingCacheImplGuava(Map<K, RefFuture<V>> level1, com.google.common.cache.LoadingCache<K, CompletableFuture<V>> level2, Map<K, V> level3, Collection<Predicate<? super K>> evictionGuards, BiConsumer<K, RefFuture<V>> claimListener, BiConsumer<K, RefFuture<V>> unclaimListener, com.google.common.cache.RemovalListener<K, V> atomicRemovalListener, Set<K> suppressedRemovalEvents) -
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.Return a snapshot of all present keysvoidvoidinvalidateAll(Iterable<? extends K> keys) static voidstatic <K,V> AsyncClaimingCacheImplGuava.Builder<K, V> newBuilder(com.google.common.cache.CacheBuilder<Object, Object> caffeine)
-
Constructor Details
-
AsyncClaimingCacheImplGuava
public AsyncClaimingCacheImplGuava(Map<K, RefFuture<V>> level1, com.google.common.cache.LoadingCache<K, CompletableFuture<V>> level2, Map<K, V> level3, Collection<Predicate<? super K>> evictionGuards, BiConsumer<K, RefFuture<V>> claimListener, BiConsumer<K, RefFuture<V>> unclaimListener, com.google.common.cache.RemovalListener<K, V> atomicRemovalListener, Set<K> suppressedRemovalEvents)
-
-
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>
-
claim
Description copied from interface:AsyncClaimingCacheClaim a reference to the key's entry.- Specified by:
claimin interfaceAsyncClaimingCache<K,V>
-
newBuilder
public static <K,V> AsyncClaimingCacheImplGuava.Builder<K,V> newBuilder(com.google.common.cache.CacheBuilder<Object, Object> caffeine) -
main
- Throws:
InterruptedException
-
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>
-
invalidateAll
- Specified by:
invalidateAllin interfaceAsyncClaimingCache<K,V>
-
getPresentKeys
Description copied from interface:AsyncClaimingCacheReturn a snapshot of all present keys- Specified by:
getPresentKeysin interfaceAsyncClaimingCache<K,V>
-