@EnableCaching
@SpringBootConfiguration
public class RedisConfig implements KeyGenerator {
@Override
public Object generate(Object o, Method method, Object... objects) {
if (objects.length == 0)
return SimpleKey.EMPTY;
else
return new SimpleKey(method.getName(),objects);
}
//配置缓存 反参格式 前缀 过期时间
@Bean
public CacheManager cacheManager(RedisConnectionFactory factory) {
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
RedisCacheConfiguration cacheConfiguration = config
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.string()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.json()))
.prefixKeysWith("project:")
.entryTtl(Duration.ofSeconds(15L));
return RedisCacheManager
.builder(factory)
.cacheDefaults(cacheConfiguration)
.build();
}
}
springboot整合redis使用@Cacheable注解的乱码处理配置及过期时间
最新推荐文章于 2024-06-05 15:51:28 发布