fix(cache): 公共 set(key,null) 改用短 null-ttl
set(key,null) 原按数据 TTL(可达 default-ttl-seconds)写入空值标记,使空标记长期 占位;改为与回源空值一致用 null-ttl-seconds(不抖动),空标记宜短。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -53,8 +53,9 @@ public class RedisCacheEnhanceTemplate {
|
||||
|
||||
public void set(String key, Object value, long ttlSeconds) {
|
||||
requirePositiveTtl(ttlSeconds);
|
||||
redis.opsForValue().set(keyBuilder.build(key), codec.encode(value),
|
||||
applyJitter(ttlSeconds), TimeUnit.SECONDS);
|
||||
// 空值(写入空标记)按短 null-ttl 处理,与回源 null 一致,避免空标记长期占位
|
||||
long ttl = (value == null) ? props.getNullTtlSeconds() : applyJitter(ttlSeconds);
|
||||
redis.opsForValue().set(keyBuilder.build(key), codec.encode(value), ttl, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// ---- 读 ----
|
||||
|
||||
Reference in New Issue
Block a user