diff --git a/README.md b/README.md index 1d23fcf..3e7d79f 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ com.pig4cloud.plugin multilevel-cache-spring-boot-starter - 0.0.3 + 0.0.4 ``` diff --git a/pom.xml b/pom.xml index 32133cd..dcd89f7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ org.springframework.boot spring-boot-starter-parent - 2.3.4.RELEASE + 2.3.5.RELEASE com.pig4cloud.plugin multilevel-cache-spring-boot-starter - 0.0.3 + 0.0.4 multilevel-cache-spring-boot-starter support L1 caffeine and L2 redis cache https://pig4cloud.com diff --git a/src/main/java/com/pig4cloud/plugin/cache/MultilevelCacheAutoConfiguration.java b/src/main/java/com/pig4cloud/plugin/cache/MultilevelCacheAutoConfiguration.java index 5129140..8ddbd8b 100755 --- a/src/main/java/com/pig4cloud/plugin/cache/MultilevelCacheAutoConfiguration.java +++ b/src/main/java/com/pig4cloud/plugin/cache/MultilevelCacheAutoConfiguration.java @@ -29,8 +29,8 @@ public class MultilevelCacheAutoConfiguration { @ConditionalOnBean(RedisTemplate.class) public RedisCaffeineCacheManager cacheManager( CacheConfigProperties cacheConfigProperties, - RedisTemplate redisTemplate) { - return new RedisCaffeineCacheManager(cacheConfigProperties, redisTemplate); + RedisTemplate stringKeyRedisTemplate) { + return new RedisCaffeineCacheManager(cacheConfigProperties, stringKeyRedisTemplate); } @Bean diff --git a/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java b/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java index e4791da..410d516 100755 --- a/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java +++ b/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java @@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.cache.support.AbstractValueAdaptingCache; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -166,6 +167,8 @@ protected Object lookup(Object key) { return value; } + // 避免自动一个 RedisTemplate 覆盖失效 + stringKeyRedisTemplate.setKeySerializer(new StringRedisSerializer()); value = stringKeyRedisTemplate.opsForValue().get(cacheKey); if (value != null) {