K
- the cache key typeV
- the result typepublic class XPFSynchronizedCacheSupportImpl<K,V> extends Object implements XPFSynchronizedCacheSupport<K,V>
1. Threads will only be blocked if there is a cache miss and there is already an evaluation running for an equivalent cache key. Lookups for different cache keys will not be blocked.
2. Only one evaluation will be executed for a cache miss of a given cache key.
3. While a cache miss evaluation is in progress, requests from separate threads for the same cache key will block until evaluation is complete and they will get the cached value after the evaluation completes.
tldr: This class virtually eliminates unnecessary cache miss evaluations and blocks threads only when a cache miss occurs for an equivalent cache key.
Modifier and Type | Field and Description |
---|---|
private com.antkorwin.xsync.XSync<K> |
xsync |
Constructor and Description |
---|
XPFSynchronizedCacheSupportImpl() |
Modifier and Type | Method and Description |
---|---|
V |
get(K cacheKey,
Function<K,V> fallbackLoaderFunction,
Function<K,XPFCacheResult<V>> checkCacheFunction,
BiFunction<K,V,V> populateCacheFunction)
Get the requested key from the cache, or use the fallback loader function if the key is not present.
|
private final com.antkorwin.xsync.XSync<K> xsync
public V get(K cacheKey, Function<K,V> fallbackLoaderFunction, Function<K,XPFCacheResult<V>> checkCacheFunction, BiFunction<K,V,V> populateCacheFunction)
XPFSynchronizedCacheSupport
get
in interface XPFSynchronizedCacheSupport<K,V>
cacheKey
- the cache key objectfallbackLoaderFunction
- the function for populating the cachecheckCacheFunction
- the function for retrieving the passed key from the cachepopulateCacheFunction
- the function for populating the cache with the passed key and valueCopyright © 2022. All rights reserved.