Commit 53743dd0bfeabf718cecdad3f596a82595fd56af

Authored by ci-aliyun
1 parent 465b6add

#feat:增加二级缓存过期时间配置项,默认120秒

src/main/java/com/irrigation/icl/cache/LayeringCacheAutoFactory.java
1 1 package com.irrigation.icl.cache;
2 2  
3   -import com.irrigation.icl.cache.config.CacheConfig;
4 3 import com.irrigation.icl.cache.core.LayeringCacheLoadCondition;
5 4 import com.irrigation.icl.cache.core.LayeringCacheManager;
6 5 import com.irrigation.icl.cache.core.LayeringCacheProperties;
7 6 import lombok.extern.slf4j.Slf4j;
8   -import org.springframework.boot.autoconfigure.AutoConfigureAfter;
9   -import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 7 import org.springframework.boot.context.properties.EnableConfigurationProperties;
11 8 import org.springframework.cache.CacheManager;
12 9 import org.springframework.context.annotation.Bean;
... ... @@ -34,7 +31,8 @@ public class LayeringCacheAutoFactory {
34 31 LayeringCacheProperties layeringCacheProperties) {
35 32 LayeringCacheManager cacheManager = new LayeringCacheManager(redisTemplate, layeringCacheProperties);
36 33 cacheManager.setUsePrefix(true);
37   - cacheManager.setDefaultExpiration(90);
  34 + long expire = layeringCacheProperties.getExpire() > 0L ? layeringCacheProperties.getExpire() : 120L;
  35 + cacheManager.setDefaultExpiration(expire);
38 36 return cacheManager;
39 37 }
40 38  
... ... @@ -64,9 +62,11 @@ public class LayeringCacheAutoFactory {
64 62 public void onMessage(Message message, byte[] pattern) {
65 63 byte[] content = message.getBody();
66 64 if (content != null) {
  65 +// String commandString = new String(content, Charset.defaultCharset());
  66 +// Command command = JSON.parseObject(commandString, Command.class);
67 67 Command command = (Command) redisTemplate.getValueSerializer().deserialize(content);
68 68 if (command != null) {
69   - log.info(command.toString());
  69 + log.debug(command.toString());
70 70 handler.handle(command);
71 71 }
72 72 }
... ...
src/main/java/com/irrigation/icl/cache/core/LayeringCacheProperties.java
... ... @@ -16,7 +16,14 @@ public class LayeringCacheProperties {
16 16 * L1缓存配置
17 17 */
18 18 private L1 cacheL1;
  19 + /**
  20 + * 是否启用缓存
  21 + */
19 22 private boolean enable = true;
  23 + /**
  24 + * L2级缓存的过期时间,单位秒
  25 + */
  26 + private long expire;
20 27  
21 28 @Data
22 29 // ehcache设置
... ...