Skip to content

Commit 7d42845

Browse files
authored
Merge pull request #9 from FlyInWind1/master
caffeine 不支持存入 null 的 value,需要包装成 NullValue
2 parents c50935f + 6b02783 commit 7d42845

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ public void put(Object key, Object value) {
9797
return;
9898
}
9999
long expire = getExpire();
100+
value = toStoreValue(value);
100101
if (expire > 0) {
101-
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value), expire, TimeUnit.MILLISECONDS);
102+
stringKeyRedisTemplate.opsForValue().set(getKey(key), value, expire, TimeUnit.MILLISECONDS);
102103
}
103104
else {
104-
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value));
105+
stringKeyRedisTemplate.opsForValue().set(getKey(key), value);
105106
}
106107

107108
push(new CacheMessage(this.name, key));
@@ -118,17 +119,17 @@ public ValueWrapper putIfAbsent(Object key, Object value) {
118119
prevValue = stringKeyRedisTemplate.opsForValue().get(cacheKey);
119120
if (prevValue == null) {
120121
long expire = getExpire();
122+
value = toStoreValue(value);
121123
if (expire > 0) {
122-
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value), expire,
123-
TimeUnit.MILLISECONDS);
124+
stringKeyRedisTemplate.opsForValue().set(getKey(key), value, expire, TimeUnit.MILLISECONDS);
124125
}
125126
else {
126-
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value));
127+
stringKeyRedisTemplate.opsForValue().set(getKey(key), value);
127128
}
128129

129130
push(new CacheMessage(this.name, key));
130131

131-
caffeineCache.put(key, toStoreValue(value));
132+
caffeineCache.put(key, value);
132133
}
133134
}
134135
return toValueWrapper(prevValue);

0 commit comments

Comments
 (0)