Interface ExpiryPolicy<K,V>
- Type Parameters:
K- the type of keys | 键类型V- the type of values | 值类型
public interface ExpiryPolicy<K,V>
Expiry Policy SPI - Cache entry expiration strategy interface
过期策略 SPI - 缓存条目过期策略接口
Provides interface for determining when cache entries should expire.
提供确定缓存条目何时过期的接口。
Features | 主要功能:
- TTL - Time To Live (expire after write) - 存活时间(写入后过期)
- TTI - Time To Idle (expire after access) - 空闲时间(访问后过期)
- Combined - Both TTL and TTI - 组合策略(同时支持 TTL 和 TTI)
- Custom - User-defined expiration - 自定义过期策略
Usage Examples | 使用示例:
// TTL - expire 1 hour after write - 写入 1 小时后过期
ExpiryPolicy<String, User> ttl = ExpiryPolicy.ttl(Duration.ofHours(1));
// TTI - expire 30 minutes after last access - 最后访问 30 分钟后过期
ExpiryPolicy<String, User> tti = ExpiryPolicy.tti(Duration.ofMinutes(30));
// Combined - 组合策略
ExpiryPolicy<String, User> combined = ExpiryPolicy.combined(
Duration.ofHours(1), Duration.ofMinutes(30));
Security | 安全性:
- Thread-safe: Yes (immutable policies) - 线程安全: 是(不可变策略)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> ExpiryPolicy <K, V> Create combined TTL and TTI policy 创建组合 TTL 和 TTI 策略static <K,V> ExpiryPolicy <K, V> eternal()Create policy that never expires 创建永不过期的策略expireAfterCreate(K key, V value) Calculate expiration duration after create 计算创建后的过期时长expireAfterRead(K key, V value, Duration currentDuration) Calculate expiration duration after read 计算读取后的过期时长expireAfterUpdate(K key, V value, Duration currentDuration) Calculate expiration duration after update 计算更新后的过期时长static <K,V> ExpiryPolicy <K, V> Create TTI (Time To Idle) policy - expire after access 创建 TTI(空闲时间)策略 - 访问后过期static <K,V> ExpiryPolicy <K, V> Create TTL (Time To Live) policy - expire after write 创建 TTL(存活时间)策略 - 写入后过期
-
Field Details
-
INFINITE
Duration indicating entry should never expire 表示条目永不过期的时长
-
-
Method Details
-
expireAfterCreate
-
expireAfterUpdate
-
expireAfterRead
-
ttl
Create TTL (Time To Live) policy - expire after write 创建 TTL(存活时间)策略 - 写入后过期- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
duration- expiration duration | 过期时长- Returns:
- TTL policy | TTL 策略
-
tti
Create TTI (Time To Idle) policy - expire after access 创建 TTI(空闲时间)策略 - 访问后过期- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
duration- expiration duration | 过期时长- Returns:
- TTI policy | TTI 策略
-
combined
Create combined TTL and TTI policy 创建组合 TTL 和 TTI 策略- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
ttl- TTL duration | TTL 时长tti- TTI duration | TTI 时长- Returns:
- combined policy | 组合策略
-
eternal
Create policy that never expires 创建永不过期的策略- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- eternal policy | 永不过期策略
-