mirror of https://github.com/elunez/eladmin
Update RedisConfig.java
1. 注释写的是 默认两小时, 但是代码写的是 6 小时, 所以应指定哪一个 ? 2. 当没有出现碰撞时, 固定的 3个 kv 对, size 达到 3 个, 如果方法参数不为空, 则会触发 HashMap 扩容, 影响性能 3 + params.length > (2^2 * 0.75 = 3) 2. 仍然引用的是 apache 的方法, 为了去除歧义, 应使用全类名指定 如果方法返回值包含 null, 则加上 @Nullable 注解, 代码更易读pull/705/head
parent
8e353ca0f7
commit
73c4e88eb9
|
@ -65,7 +65,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
FastJsonRedisSerializer<Object> fastJsonRedisSerializer = new FastJsonRedisSerializer<>(Object.class);
|
||||
RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig();
|
||||
configuration = configuration.serializeValuesWith(RedisSerializationContext.
|
||||
SerializationPair.fromSerializer(fastJsonRedisSerializer)).entryTtl(Duration.ofHours(6));
|
||||
SerializationPair.fromSerializer(fastJsonRedisSerializer)).entryTtl(Duration.ofHours(2));
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
@Override
|
||||
public KeyGenerator keyGenerator() {
|
||||
return (target, method, params) -> {
|
||||
Map<String,Object> container = new HashMap<>(3);
|
||||
Map<String,Object> container = new HashMap<>();
|
||||
Class<?> targetClassClass = target.getClass();
|
||||
// 类地址
|
||||
container.put("class",targetClassClass.toGenericString());
|
||||
|
@ -204,9 +204,10 @@ class StringRedisSerializer implements RedisSerializer<Object> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(Object object) {
|
||||
public @Nullable byte[] serialize(Object object) {
|
||||
String string = JSON.toJSONString(object);
|
||||
if (StringUtils.isBlank(string)) {
|
||||
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(string)) {
|
||||
return null;
|
||||
}
|
||||
string = string.replace("\"", "");
|
||||
|
|
Loading…
Reference in New Issue