java.lang.Object
org.apache.jena.atlas.lib.cache.CacheCaffeine<K,V>
- All Implemented Interfaces:
Cache<K,V>
Wrapper around a com.github.benmanes.caffeine
-
Constructor Summary
ConstructorsConstructorDescriptionCacheCaffeine(int size) CacheCaffeine(int size, BiConsumer<K, V> dropHandler) CacheCaffeine(int size, BiConsumer<K, V> dropHandler, double initialCapacityFactor) CacheCaffeine(com.github.benmanes.caffeine.cache.Cache<K, V> caffeine) -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanUp()Forces the cache to clean up stale entriesvoidclear()booleancontainsKey(K key) Does the cache contain the key?Get from cache; if not present, call theFunctionto fill the cache slot.getIfPresent(K key) Get from cache - or return null.booleanisEmpty()keys()Iterate over all keys.voidInsert into the cachevoidRemove from cache - return true if key referenced an entrylongsize()Current size of cache
-
Constructor Details
-
CacheCaffeine
public CacheCaffeine(int size) -
CacheCaffeine
-
CacheCaffeine
-
CacheCaffeine
-
-
Method Details
-
get
Description copied from interface:CacheGet from cache; if not present, call theFunctionto fill the cache slot. This operation should be atomic.- Specified by:
getin interfaceCache<K,V> - Parameters:
key- The key, for which the value should be returned or calculated. The key must not be null.f- If the cache does not contain the key, the callable is called to calculate a value. If the callable returns null, the key is not associated with hat value, as nulls are not accepted as values. The callable must not be null.- Returns:
- Returns either the existing value or the calculated value. If callable is called and returns null, then null is returned.
-
getIfPresent
Description copied from interface:CacheGet from cache - or return null.- Specified by:
getIfPresentin interfaceCache<K,V> - Parameters:
key- The key for which the value is requested. The key must not be null.- Returns:
- If the cache contains an entry for the given key, the value is returned, otherwise null.
-
put
Description copied from interface:CacheInsert into the cache -
containsKey
Description copied from interface:CacheDoes the cache contain the key?- Specified by:
containsKeyin interfaceCache<K,V> - Parameters:
key- The key to find. The key must not be null.- Returns:
- True, if the cache contains the key, otherwise false.
-
remove
Description copied from interface:CacheRemove from cache - return true if key referenced an entry -
keys
Description copied from interface:CacheIterate over all keys. Iterating over the keys requires the caller be thread-safe. -
isEmpty
public boolean isEmpty() -
clear
public void clear() -
size
public long size()Description copied from interface:CacheCurrent size of cache -
cleanUp
public void cleanUp()Forces the cache to clean up stale entries
-