Interface AsyncCacheLoader<K,V>
- Type Parameters:
K- the type of keys | 键类型V- the type of values | 值类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Async Cache Loader SPI - Asynchronous cache value loader interface
异步缓存加载器 SPI - 异步缓存值加载接口
Provides interface for asynchronously loading cache values when not present.
提供缓存值不存在时的异步加载接口。
Features | 主要功能:
- Async single value loading - 异步单值加载
- Async batch loading - 异步批量加载
- Async reload/refresh - 异步重新加载/刷新
Usage Examples | 使用示例:
AsyncCacheLoader<String, User> loader = (key, executor) ->
CompletableFuture.supplyAsync(() -> userDao.findById(key), executor);
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Null-safe: Future may complete with null - 空值安全: Future 可能以 null 完成
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAsync load value for single key 异步加载单个键的值default CompletableFuture<Map<K, V>> asyncLoadAll(Set<? extends K> keys, Executor executor) Async batch load values 异步批量加载值default CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) Async reload value 异步重新加载值static <K,V> AsyncCacheLoader <K, V> from(CacheLoader<K, V> loader) Create from sync loader 从同步加载器创建
-
Method Details
-
asyncLoad
Async load value for single key 异步加载单个键的值- Parameters:
key- the key | 键executor- the executor | 执行器- Returns:
- future containing value | 包含值的 Future
-
asyncLoadAll
-
asyncReload
Async reload value 异步重新加载值- Parameters:
key- the key | 键oldValue- the old value | 旧值executor- the executor | 执行器- Returns:
- future containing new value | 包含新值的 Future
-
from
Create from sync loader 从同步加载器创建- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
loader- sync loader | 同步加载器- Returns:
- async loader | 异步加载器
-