Interface AsyncCacheLoader<K,V>
- Type Parameters:
K- key type (must be non-null)V- value type (must be non-null)
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Asynchronous functional interface for loading values in cache-aside pattern.
Implementations should load a value asynchronously from an upstream source (database, API, etc.)
when the cache experiences a miss. This is the async counterpart of CacheLoader.
Thread Safety
Implementations must be thread-safe as they may be called from multiple threads concurrently.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Map<K, V>> loadAllAsync(Collection<K> keys) Asynchronously load values for all given keys.Asynchronously load a value for the given key.
-
Method Details
-
loadAsync
Asynchronously load a value for the given key.- Parameters:
key- the key to load (must not be null)- Returns:
- a future that completes with the loaded value (must not complete with null)
- Throws:
NullPointerException- if key is null
-
loadAllAsync
Asynchronously load values for all given keys.The default implementation calls
loadAsync(Object)for each key individually and combines the results. Override this method to provide a more efficient bulk-loading implementation (e.g., a single batch query).Keys whose futures complete exceptionally are silently skipped in the result map.
- Parameters:
keys- the keys to load (must not be null, must not contain null elements)- Returns:
- a future that completes with a map of successfully loaded key-value pairs
- Throws:
NullPointerException- if keys is null
-