K - The key, usually used to identify if the computation has already been performedV - The value, usually representing the result of the computation associated to the keypublic class FIFOThreadSafeCache<K,V> extends Object implements Serializable
The tread-safety is handled by the use of the ConcurrentLinkedDeque implementation (which is a lock-free
implementation).
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_SIZE
Default max size for the cache: trade-off between the duration for look-up in the cache versus reuse of already
computed values.
|
static int |
PERCENT
Percent conversion value.
|
| Constructor and Description |
|---|
FIFOThreadSafeCache()
Constructor with default max size
DEFAULT_MAX_SIZE. |
FIFOThreadSafeCache(int listMaxSize)
Standard constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the cache.
|
CacheEntry<K,V> |
computeIf(Predicate<CacheEntry<K,V>> cacheAvailabilityPredicate,
Supplier<CacheEntry<K,V>> entrySupplier)
Computes and add a new entry in the cache, if necessary.
|
CacheEntry<K,V> |
computeIfAbsent(K key,
Supplier<CacheEntry<K,V>> entrySupplier)
Computes and add a new entry in the cache, if necessary.
|
int |
getMaxSize()
Getter for the maximum size of the cache.
|
double |
getReusabilityRatio()
Provides the ratio of reusability of this cache.
|
String |
toString()
Returns a string representation of the cache structure.
|
public static final int DEFAULT_MAX_SIZE
public static final int PERCENT
public FIFOThreadSafeCache()
DEFAULT_MAX_SIZE.public FIFOThreadSafeCache(int listMaxSize)
listMaxSize - The max size of the cache. 0 is a legitimate value emulating the absence of cache.NotPositiveException - if listMaxSize < 0public CacheEntry<K,V> computeIf(Predicate<CacheEntry<K,V>> cacheAvailabilityPredicate, Supplier<CacheEntry<K,V>> entrySupplier)
cacheAvailabilityPredicate - The predicate that test if one of the entries of the cache matches the requiremententrySupplier - The supplier that will build the entry if required. If it returns null, the entry will be returned
normally but not added into the cache.null if the supplier provided such a value.public CacheEntry<K,V> computeIfAbsent(K key, Supplier<CacheEntry<K,V>> entrySupplier)
key - The key to assess if the computation is requiredentrySupplier - The supplier that will build the entry if requiredpublic void clear()
computeIf(java.util.function.Predicate<fr.cnes.sirius.patrius.tools.cache.CacheEntry<K, V>>, java.util.function.Supplier<fr.cnes.sirius.patrius.tools.cache.CacheEntry<K, V>>) (more
precisely with addEntry internal method).public int getMaxSize()
public double getReusabilityRatio()
This method can help to chose the size of the cache.
computeIf(Predicate, Supplier) method)Copyright © 2025 CNES. All rights reserved.