在springboot1.x
系列中,spring-boot-starter-data-redis包客户端使用的是jedis
,但是到了springboot2.x
其中使用的是Lettuce
。
用redis做缓存时,有以下两种方式:
①与spring-cache集成,查询时缓存,增删改时删除缓存
②写个redis工具类,自己在需要的地方写插入和查询的方法
可以同时使用ehcache做系统缓存和hibernate的二级缓存
spring:
jpa:
properties:
hibernate:
cache:
# 二级缓存 针对实体的
use_second_level_cache: true
provider_configuration_file_resource_path: ehcache-hibernate.xml
region:
factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
cache:
type: ehcache
ehcache:
config: classpath:ehcache-spring.xml
问题是我想同时用redis和ehcache 和spring-cache集成做系统缓存,同时又用ehcache做hibernate的二级缓存,
这就尴尬了。
①yml中配置系统ehcache,java config 配置redisCache,redis会覆盖掉ehcache,如下源码。