spring-boot-starter-cache设置
作者:互联网
一、SpringBoot 2.x的配置方法;
1、通过spring-boot-starter-cache导入依赖;
2、spring-boot-autoconfigureCache的CacheAutoConfiguration负责全局的cache管理,RedisCacheConfiguration负责redis cache的配置;
3、RedisCacheConfiguration内有@Bean public RedisCacheManager cacheManager()方法,通过6个入参来设置RedisCacheManager;
4、一般我们通过两个入参来控制RedisCacheManager的构建:
- ObjectProvider<org.springframework.data.redis.cache.RedisCacheConfiguration> redisCacheConfiguration
- ObjectProvider<RedisCacheManagerBuilderCustomizer> redisCacheManagerBuilderCustomizers
5、相关链接:spring-boot-redis-cache,how-to-create-rediscachemanager-in-spring-data-2-0-x
二、SpringBoot 1.x的配置方法;
1、第一步相同;
2、第二步相同;
3、RedisCacheConfiguration内有@Bean public RedisCacheManager cacheManager(),通过入参RedisTemplate<Object, Object> redisTemplate来控制
4、我们在spring-boot-autoconfigureCache的RedisAutoConfiguration设置RedisTemplate
三、Jedis vs Lettuce和commons-pool2
1、1.x时默认为Jedis,2.x时默认为Lettuce(需要引入commons-pool2作为连接池);
2、如果2.x环境需要设置Jedis为默认Driver,可以参考 Use Jedis Instead of Lettuce
标签:RedisCacheManager,spring,cache,boot,RedisCacheConfiguration,Jedis 来源: https://www.cnblogs.com/echo1937/p/14854875.html