Package org.aksw.commons.cache.async
Class AsyncRefCache<K,V>
java.lang.Object
org.aksw.commons.cache.async.AsyncRefCache<K,V>
- Type Parameters:
K-V-
A wrapper around a cache that on each lookup returns a fresh CompletableFuture that
can be cancelled independently. Only if all 'slave' futures are cancelled then the
'master' future is cancelled.
Once a master's future is loaded then the slave futures will close themselves
as the loading can no longer be interrupted.
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe cache with the primary loaderA 'slave' map that wraps the completable futures of the master as a ref The slave is synchronized with the master - it atomically contains the same keys. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> AsyncRefCache<K, V> create(com.github.benmanes.caffeine.cache.Caffeine<Object, Object> master, Function<K, V> cacheLoader, com.github.benmanes.caffeine.cache.RemovalListener<K, V> removalListener) Whether to cancel loading of items that were unclaimed before loading completed, if false, the future returned by the master will not be cancelledgetAsCompletableFuture(K key) Get a fresh complatable future to the key.getAsRefFuture(K key) Get a fresh reference to the item corresponding to 'key'.getIfPresent(K key) voidstatic voidvoid
-
Field Details
-
master
The cache with the primary loader -
slave
A 'slave' map that wraps the completable futures of the master as a ref The slave is synchronized with the master - it atomically contains the same keys.
-
-
Constructor Details
-
AsyncRefCache
-
-
Method Details
-
create
public static <K,V> AsyncRefCache<K,V> create(com.github.benmanes.caffeine.cache.Caffeine<Object, Object> master, Function<K, V> cacheLoader, com.github.benmanes.caffeine.cache.RemovalListener<K, V> removalListener) Whether to cancel loading of items that were unclaimed before loading completed, if false, the future returned by the master will not be cancelled -
getAsCompletableFuture
Get a fresh complatable future to the key. Cannot be used if a close action on items is configured, because completion of the future would close the item. -
put
-
getAsRefFuture
Get a fresh reference to the item corresponding to 'key'.- Parameters:
key-- Returns:
-
main
-
getIfPresent
-
invalidateAll
public void invalidateAll()
-