# spring boot data jpa 2.2 开启redis二级缓存 **Repository Path**: tianchaohongyu/spring-boot-data-jpa-redis-second-cache ## Basic Information - **Project Name**: spring boot data jpa 2.2 开启redis二级缓存 - **Description**: spring boot data jpa 2.2 开启redis二级缓存 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 3 - **Created**: 2019-12-09 - **Last Updated**: 2021-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spring boot data jpa 2.2.2 开启二级缓存 #### 介绍 spring boot data jpa 2.2.2 开启二级缓存指引 ### 在application.properties中配置: ```properties #显示sql spring.jpa.properties.hibernate.show_sql=true #开启二级缓存 spring.jpa.properties.hibernate.cache.use_second_level_cache=true spring.jpa.properties.hibernate.cache.use_query_cache=true #基于 jcache(不推荐) :https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#caching #spring.jpa.properties.hibernate.cache.region.factory_class=jcache #spring.jpa.properties.hibernate.javax.cache.cache_manager=com.gitee.tianchaohongyu.example.cache.RedissonCacheManager #redisson hibernate 二级缓存,见:https://github.com/redisson/redisson/tree/master/redisson-hibernate spring.jpa.properties.hibernate.cache.region.factory_class=org.redisson.hibernate.RedissonRegionFactory #redisson配置文件路径 spring.jpa.properties.hibernate.cache.redisson.config=./src/main/resources/redisson.json #缓存的最大大小。使用LRU算法驱逐Redis中的多余条目。 spring.jpa.properties.hibernate.cache.redisson[com.gitee.tianchaohongyu.example.entity.User].eviction.max_entrie=2 # 每个缓存条目在Redis中的存活时间。以毫秒为单位定义。 spring.jpa.properties.hibernate.cache.redisson[com.gitee.tianchaohongyu.example.entity.User].expiration.time_to_live=30000 # Redis中每个缓存条目的最大空闲时间。以毫秒为单位定义。 spring.jpa.properties.hibernate.cache.redisson[com.gitee.tianchaohongyu.example.entity.User].expiration.max_idle_time=30000 ```