Class ReadThroughCache<K,V>
java.lang.Object
com.loomcache.client.cache.ReadThroughCache<K,V>
- Type Parameters:
K- key typeV- value type
Read-through cache that implements the cache-aside pattern.
When a cache miss occurs, the CacheLoader is called to fetch the value.
Multiple concurrent requests for the same key are coalesced — only one loader call
is made, and all threads block on the same CompletableFuture result.
-
Constructor Summary
ConstructorsConstructorDescriptionReadThroughCache(NearCache<K, V> nearCache, CacheLoader<K, V> loader) Create a new read-through cache. -
Method Summary
Modifier and TypeMethodDescriptionGet a value from the cache, loading it if necessary.getAll(Collection<K> keys) Get multiple values, loading any missing ones efficiently.getStats()Get underlying near cache statistics.Refresh a specific key by forcing a reload from the source.voidRefresh all entries by clearing the near cache.
-
Constructor Details
-
ReadThroughCache
Create a new read-through cache.- Parameters:
nearCache- the underlying near cache (must not be null)loader- the cache loader for cache misses (must not be null)- Throws:
NullPointerException- if any parameter is null
-
-
Method Details
-
get
Get a value from the cache, loading it if necessary.If multiple threads request the same missing key simultaneously, only one will call the loader; others will wait on the same future.
- Parameters:
key- the key to retrieve- Returns:
- the cached value
- Throws:
Exception- if the loader fails
-
getAll
-
refresh
-
refreshAll
public void refreshAll()Refresh all entries by clearing the near cache. -
getStats
Get underlying near cache statistics.
-