Class CacheConfig<K,V>
java.lang.Object
cloud.opencode.base.cache.config.CacheConfig<K,V>
- Type Parameters:
K- the type of keys | 键类型V- the type of values | 值类型
Cache Configuration - Immutable cache configuration with Builder pattern
缓存配置 - 不可变的缓存配置,使用 Builder 模式
Provides comprehensive cache configuration options including size limits, expiration policies, eviction policies, and async execution settings.
提供全面的缓存配置选项,包括容量限制、过期策略、淘汰策略和异步执行设置。
Features | 主要功能:
- Size/Weight limits - 容量/权重限制
- TTL/TTI expiration - TTL/TTI 过期
- Eviction policies (LRU/LFU/FIFO/W-TinyLFU) - 淘汰策略
- Removal listener - 移除监听器
- Statistics recording - 统计记录
- Virtual thread support - 虚拟线程支持
Usage Examples | 使用示例:
CacheConfig<String, User> config = CacheConfig.<String, User>builder()
.maximumSize(10000)
.expireAfterWrite(Duration.ofMinutes(30))
.expireAfterAccess(Duration.ofMinutes(10))
.recordStats()
.build();
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCache Configuration Builder 缓存配置构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> CacheConfig.Builder <K, V> builder()Create new builder 创建新的构建器intReturns the concurrency level | 返回并发级别static <K,V> CacheConfig <K, V> Create default configuration 创建默认配置Returns the eviction policy | 返回淘汰策略executor()Returns the executor | 返回执行器Returns the expire-after-access duration | 返回访问后过期时间Returns the expire-after-write duration | 返回写入后过期时间Returns the expiry policy | 返回过期策略booleanCheck if expiration is configured 检查是否配置了过期booleanCheck if size limit is configured 检查是否配置了容量限制intReturns the initial capacity | 返回初始容量loader()Returns the cache loader | 返回缓存加载器longReturns the maximum size | 返回最大大小longReturns the maximum weight | 返回最大权重booleanReturns whether stats recording is enabled | 返回是否启用统计记录Returns the refresh-after-write duration | 返回写入后刷新时间Get refresh ahead policy 获取提前刷新策略Returns the removal listener | 返回移除监听器booleanReturns whether virtual threads are used | 返回是否使用虚拟线程weigher()Get value weigher 获取值权重计算器
-
Method Details
-
maximumSize
public long maximumSize()Returns the maximum size | 返回最大大小- Returns:
- maximum size | 最大大小
-
maximumWeight
public long maximumWeight()Returns the maximum weight | 返回最大权重- Returns:
- maximum weight | 最大权重
-
expireAfterWrite
Returns the expire-after-write duration | 返回写入后过期时间- Returns:
- expire-after-write | 写入后过期时间
-
expireAfterAccess
Returns the expire-after-access duration | 返回访问后过期时间- Returns:
- expire-after-access | 访问后过期时间
-
refreshAfterWrite
Returns the refresh-after-write duration | 返回写入后刷新时间- Returns:
- refresh-after-write | 写入后刷新时间
-
evictionPolicy
Returns the eviction policy | 返回淘汰策略- Returns:
- eviction policy | 淘汰策略
-
expiryPolicy
Returns the expiry policy | 返回过期策略- Returns:
- expiry policy | 过期策略
-
loader
-
removalListener
Returns the removal listener | 返回移除监听器- Returns:
- removal listener | 移除监听器
-
recordStats
public boolean recordStats()Returns whether stats recording is enabled | 返回是否启用统计记录- Returns:
- true if stats enabled | 启用统计返回 true
-
useVirtualThreads
public boolean useVirtualThreads()Returns whether virtual threads are used | 返回是否使用虚拟线程- Returns:
- true if virtual threads | 使用虚拟线程返回 true
-
executor
-
concurrencyLevel
public int concurrencyLevel()Returns the concurrency level | 返回并发级别- Returns:
- concurrency level | 并发级别
-
initialCapacity
public int initialCapacity()Returns the initial capacity | 返回初始容量- Returns:
- initial capacity | 初始容量
-
refreshAheadPolicy
Get refresh ahead policy 获取提前刷新策略- Returns:
- refresh ahead policy | 提前刷新策略
-
weigher
-
hasExpiration
public boolean hasExpiration()Check if expiration is configured 检查是否配置了过期- Returns:
- true if expiration configured | 配置了过期返回 true
-
hasSizeLimit
public boolean hasSizeLimit()Check if size limit is configured 检查是否配置了容量限制- Returns:
- true if size limit configured | 配置了容量限制返回 true
-
builder
Create new builder 创建新的构建器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new builder | 新构建器
-
defaultConfig
Create default configuration 创建默认配置- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- default config | 默认配置
-