Skip to content

Commit

Permalink
Merge pull request #9 from FlyInWind1/master
Browse files Browse the repository at this point in the history
caffeine 不支持存入 null 的 value,需要包装成 NullValue
  • Loading branch information
lltx committed Jan 12, 2022
2 parents c50935f + 6b02783 commit 7d42845
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ public void put(Object key, Object value) {
return;
}
long expire = getExpire();
value = toStoreValue(value);
if (expire > 0) {
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value), expire, TimeUnit.MILLISECONDS);
stringKeyRedisTemplate.opsForValue().set(getKey(key), value, expire, TimeUnit.MILLISECONDS);
}
else {
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value));
stringKeyRedisTemplate.opsForValue().set(getKey(key), value);
}

push(new CacheMessage(this.name, key));
Expand All @@ -118,17 +119,17 @@ public ValueWrapper putIfAbsent(Object key, Object value) {
prevValue = stringKeyRedisTemplate.opsForValue().get(cacheKey);
if (prevValue == null) {
long expire = getExpire();
value = toStoreValue(value);
if (expire > 0) {
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value), expire,
TimeUnit.MILLISECONDS);
stringKeyRedisTemplate.opsForValue().set(getKey(key), value, expire, TimeUnit.MILLISECONDS);
}
else {
stringKeyRedisTemplate.opsForValue().set(getKey(key), toStoreValue(value));
stringKeyRedisTemplate.opsForValue().set(getKey(key), value);
}

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

caffeineCache.put(key, toStoreValue(value));
caffeineCache.put(key, value);
}
}
return toValueWrapper(prevValue);
Expand Down

0 comments on commit 7d42845

Please sign in to comment.