Interface RemovalListener<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.
Removal Listener SPI - Cache entry removal callback interface
移除监听器 SPI - 缓存条目移除回调接口
Provides callback when cache entries are removed for any reason.
当缓存条目因任何原因被移除时提供回调。
Features | 主要功能:
- Notification on entry removal - 条目移除时通知
- Access to removal cause - 访问移除原因
- Logging and auditing - 日志和审计
Usage Examples | 使用示例:
RemovalListener<String, User> listener = (key, value, cause) -> {
if (cause.wasEvicted()) {
log.info("User cache evicted: {}", key);
}
};
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Null-safe: value may be null - 空值安全: value 可能为 null
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> RemovalListener <K, V> combine(RemovalListener<K, V>... listeners) Combine multiple listeners 组合多个监听器static <K,V> RemovalListener <K, V> logging()Create a listener that logs removals 创建一个记录移除日志的监听器static <K,V> RemovalListener <K, V> noOp()Create a listener that does nothing 创建一个什么都不做的监听器voidonRemoval(K key, V value, RemovalCause cause) Called when an entry is removed from cache 当条目从缓存中移除时调用
-
Method Details
-
onRemoval
Called when an entry is removed from cache 当条目从缓存中移除时调用- Parameters:
key- the key being removed | 被移除的键value- the value being removed (may be null) | 被移除的值(可能为 null)cause- the removal cause | 移除原因
-
noOp
Create a listener that does nothing 创建一个什么都不做的监听器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- no-op listener | 空操作监听器
-
logging
Create a listener that logs removals 创建一个记录移除日志的监听器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- logging listener | 日志监听器
-
combine
Combine multiple listeners 组合多个监听器- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
listeners- the listeners | 监听器列表- Returns:
- combined listener | 组合后的监听器
-