Class MemoryNonceCache
java.lang.Object
tech.riemann.nif.web.sign.MemoryNonceCache
- All Implemented Interfaces:
NonceCache
基于内存的Nonce缓存实现
适用于单节点部署
特点:
1. 高性能,无需网络开销
2. 条目级动态过期(M1 修复:按 expireSeconds 逐条设置过期,原实现写死 5 分钟)
3. 线程安全,支持并发访问(putIfAbsent / replace 原子操作)
4. 硬上限 10 万条,防内存 DoS
生效方式:默认注册为 NonceCache Bean;业务方注册自定义 NonceCache Bean 时,
本实现通过 @ConditionalOnMissingBean 自动让位。无 nonce-cache-type 之类的类型开关。
- Author:
- Kerbores(kerbores@riemann.tech)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleansetIfAbsent(String nonce, String value, long expireSeconds) 若 nonce 不存在则设置(含"已存在但已过期"场景的原子复用)
-
Constructor Details
-
MemoryNonceCache
public MemoryNonceCache()
-
-
Method Details
-
setIfAbsent
若 nonce 不存在则设置(含"已存在但已过期"场景的原子复用)过期语义(M1):按传入的
expireSeconds逐条设置过期时间——@SignVerify(expireSeconds=60)配 1 分钟即 1 分钟失效,不再写死 5 分钟- Specified by:
setIfAbsentin interfaceNonceCache- Parameters:
nonce- nonce值value- 存储的值expireSeconds- 过期时间(秒)- Returns:
- 是否设置成功(false 表示已存在且未过期)
-