Class CacheConfig.Builder<K,V>
java.lang.Object
cloud.opencode.base.cache.config.CacheConfig.Builder<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- Enclosing class:
CacheConfig<K,V>
Cache Configuration Builder
缓存配置构建器
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the configuration 构建配置concurrencyLevel(int level) Set concurrency level 设置并发级别diagnose()Get validation diagnostics without throwing exceptions 获取验证诊断信息,不抛出异常evictionPolicy(EvictionPolicy<K, V> policy) Set eviction policy 设置淘汰策略Set custom executor for async operations 设置自定义执行器用于异步操作expireAfterAccess(Duration duration) Set expiration after access (TTI) 设置访问后过期时间(TTI)expireAfterWrite(Duration duration) Set expiration after write (TTL) 设置写入后过期时间(TTL)expiryPolicy(ExpiryPolicy<K, V> policy) Set expiry policy 设置过期策略initialCapacity(int capacity) Set initial capacity 设置初始容量loader(CacheLoader<K, V> loader) Set cache loader 设置缓存加载器Set cache loader from function 从函数设置缓存加载器maximumSize(long size) Set maximum entry count 设置最大条目数maximumWeight(long weight) Set maximum weight 设置最大权重Enable statistics recording 启用统计记录refreshAfterWrite(Duration duration) Set refresh after write duration 设置写入后刷新时间refreshAheadPolicy(RefreshAheadPolicy<K, V> policy) Set refresh ahead policy for proactive cache refresh 设置提前刷新策略用于主动缓存刷新removalListener(RemovalListener<K, V> listener) Set removal listener 设置移除监听器Enable virtual threads for async operations 启用虚拟线程用于异步操作voidvalidate()Validate the configuration 验证配置weigher(ValueWeigher<V> weigher) Set value weigher for memory-based eviction 设置值权重计算器用于基于内存的淘汰
-
Constructor Details
-
Builder
public Builder()Creates a new Builder instance | 创建新的构建器实例
-
-
Method Details
-
maximumSize
Set maximum entry count 设置最大条目数Note: Setting maximumSize automatically clears maximumWeight to avoid conflicts. Use one or the other.
- Parameters:
size- maximum size | 最大容量- Returns:
- this builder | 此构建器
-
maximumWeight
Set maximum weight 设置最大权重Note: Setting maximumWeight automatically clears maximumSize to avoid conflicts. Use one or the other.
- Parameters:
weight- maximum weight | 最大权重- Returns:
- this builder | 此构建器
-
expireAfterWrite
Set expiration after write (TTL) 设置写入后过期时间(TTL)- Parameters:
duration- expiration duration | 过期时长- Returns:
- this builder | 此构建器
-
expireAfterAccess
Set expiration after access (TTI) 设置访问后过期时间(TTI)- Parameters:
duration- expiration duration | 过期时长- Returns:
- this builder | 此构建器
-
refreshAfterWrite
Set refresh after write duration 设置写入后刷新时间- Parameters:
duration- refresh duration | 刷新时长- Returns:
- this builder | 此构建器
-
evictionPolicy
Set eviction policy 设置淘汰策略- Parameters:
policy- eviction policy | 淘汰策略- Returns:
- this builder | 此构建器
-
expiryPolicy
Set expiry policy 设置过期策略- Parameters:
policy- expiry policy | 过期策略- Returns:
- this builder | 此构建器
-
loader
Set cache loader 设置缓存加载器- Parameters:
loader- cache loader | 缓存加载器- Returns:
- this builder | 此构建器
-
loader
-
removalListener
Set removal listener 设置移除监听器- Parameters:
listener- removal listener | 移除监听器- Returns:
- this builder | 此构建器
-
recordStats
Enable statistics recording 启用统计记录- Returns:
- this builder | 此构建器
-
useVirtualThreads
Enable virtual threads for async operations 启用虚拟线程用于异步操作- Returns:
- this builder | 此构建器
-
executor
Set custom executor for async operations 设置自定义执行器用于异步操作- Parameters:
executor- the executor | 执行器- Returns:
- this builder | 此构建器
-
concurrencyLevel
Set concurrency level 设置并发级别- Parameters:
level- concurrency level | 并发级别- Returns:
- this builder | 此构建器
-
initialCapacity
Set initial capacity 设置初始容量- Parameters:
capacity- initial capacity | 初始容量- Returns:
- this builder | 此构建器
-
refreshAheadPolicy
Set refresh ahead policy for proactive cache refresh 设置提前刷新策略用于主动缓存刷新- Parameters:
policy- refresh ahead policy | 提前刷新策略- Returns:
- this builder | 此构建器
-
weigher
Set value weigher for memory-based eviction 设置值权重计算器用于基于内存的淘汰- Parameters:
weigher- value weigher | 值权重计算器- Returns:
- this builder | 此构建器
-
build
Build the configuration 构建配置- Returns:
- cache config | 缓存配置
- Throws:
IllegalArgumentException- if configuration is invalid | 配置无效时抛出异常
-
validate
public void validate()Validate the configuration 验证配置- Throws:
IllegalArgumentException- if configuration is invalid | 配置无效时抛出异常- Since:
- V2.0.2
-
diagnose
-