Commit 53743dd0bfeabf718cecdad3f596a82595fd56af
1 parent
465b6add
#feat:增加二级缓存过期时间配置项,默认120秒
Showing
2 changed files
with
12 additions
and
5 deletions
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