代码片段: SpringBoot2.0-gistfile1.txt

// 配置方式1 @Bean public RedisCacheManager getRedisCacheManager(@Autowired ConfigHolder config,RedisConnectionFactory connectionFactory){ RedisCacheWriter cacheWrit...
<pre>// 配置方式1 @Bean public RedisCacheManager getRedisCacheManager(@Autowired ConfigHolder config,RedisConnectionFactory connectionFactory){ RedisCacheWriter cacheWriter = RedisCacheWriter.lockingRedisCacheWriter(connectionFactory); ClassLoader loader = this.getClass().getClassLoader(); JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer(loader); RedisSerializationContext.SerializationPair<Object> pair = RedisSerializationContext.SerializationPair.fromSerializer(jdkSerializer); RedisCacheConfiguration cacheConfig = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair).entryTtl(Duration.ofSeconds(config.getCacheTtl().longValue())); return new RedisCacheManager(cacheWriter, cacheConfig); } // 配置方式2 @Bean public CacheManager jedisCacheManager(@Autowired ConfigHolder config,@Autowired CacheCloudConnectionFactory cf) { RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofSeconds(config.getCacheTtl().longValue())); RedisCacheManager.RedisCacheManagerBuilder cacheManagerBuilder = RedisCacheManager.builder(cf); cacheManagerBuilder.cacheDefaults(cacheConfiguration); return cacheManagerBuilder.build(); }</pre>
  • 发表于 2018-04-22 23:20
  • 阅读 ( 29 )
  • 分类:代码片段

0 条评论

请先 登录 后评论
不写代码的码农
网文小编

0 篇文章

作家榜 »

  1. 网文小编 0 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除