RedisCache的问题
RedisCache是先判断key是否存在,不存在返回null;存在再获取值,存在并发问题。当key存在并获取值时,缓存被别的线程删除了,则返回值就为null了。
修改方案:先从redis查询值,再判断key是否存在。
自定义RedisCacheManger
public class CustomizedRedisCacheManager extends RedisCacheManager {
public CustomizedRedisCacheManager(RedisOperations redisOperations) {
super(redisOperations);
}
public CustomizedRedisCacheManager(RedisOperations redisOperations, Collection<String> cacheNames) {
super(redisOperations, cacheNames);
}
@Override
protected Cache getMissingCache(String name) {
long expiration = computeExpiration(name);
return new CustomizedRedisCache(name, (this.isUsePrefix() ? this.getCach