Interface CacheWarmer<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.
Cache Warmer SPI - Cache pre-warming interface
缓存预热器 SPI - 缓存预热接口
Provides interface for pre-loading cache data at application startup.
提供应用启动时预加载缓存数据的接口。
Features | 主要功能:
- Sync/Async warming - 同步/异步预热
- Priority-based loading - 基于优先级的加载
- Completion callbacks - 完成回调
- Paged loading support - 分页加载支持
Usage Examples | 使用示例:
CacheWarmer<Long, Product> warmer = () -> {
return productDao.findHotProducts(1000).stream()
.collect(Collectors.toMap(Product::getId, p -> p));
};
// With paged loading - 分页加载
CacheWarmer<Long, Product> pagedWarmer = CacheWarmer.paged(
offset -> productDao.findProducts(offset, 100),
100, 10);
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> CacheWarmer <K, V> empty()Create empty warmer 创建空预热器static <K,V> CacheWarmer <K, V> Create warmer from supplier 从 Supplier 创建预热器default booleanCheck if warming is enabled 检查是否启用预热default voidonComplete(int loadedCount, Duration duration) Called when warm-up completes 预热完成时调用default voidCalled when warm-up fails 预热失败时调用static <K,V> CacheWarmer <K, V> Create paged loading warmer 创建分页加载预热器default intpriority()Get warm-up priority (lower = higher priority) 获取预热优先级(数值越小优先级越高)warmUp()Perform warm-up and return data to load 执行预热并返回要加载的数据default CompletableFuture<Map<K, V>> warmUpAsync(Executor executor) Async warm-up 异步预热
-
Method Details
-
warmUp
-
warmUpAsync
Async warm-up 异步预热- Parameters:
executor- the executor | 执行器- Returns:
- future containing data | 包含数据的 Future
-
priority
default int priority()Get warm-up priority (lower = higher priority) 获取预热优先级(数值越小优先级越高)- Returns:
- priority | 优先级
-
isEnabled
default boolean isEnabled()Check if warming is enabled 检查是否启用预热- Returns:
- true if enabled | 启用返回 true
-
onComplete
Called when warm-up completes 预热完成时调用- Parameters:
loadedCount- number of entries loaded | 加载的条目数duration- warm-up duration | 预热耗时
-
onError
Called when warm-up fails 预热失败时调用- Parameters:
cause- failure cause | 失败原因
-
from
Create warmer from supplier 从 Supplier 创建预热器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
supplier- data supplier | 数据供应器- Returns:
- warmer | 预热器
-
paged
static <K,V> CacheWarmer<K,V> paged(Function<Integer, Map<K, V>> pageLoader, int pageSize, int maxPages) Create paged loading warmer 创建分页加载预热器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
pageLoader- page loader function | 分页加载函数pageSize- page size | 页大小maxPages- max pages to load | 最大加载页数- Returns:
- warmer | 预热器
-
empty
Create empty warmer 创建空预热器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- empty warmer | 空预热器
-