二级缓存
-
Hiberante二级缓存
Hibernate的缓存:
一级缓存:session级缓存
二级缓存:sessionFactory级缓存,用处很大(线程级:ehcache)
三级缓存:分布式缓存(进程级:redis) -
缓存分类
- 实体缓存:根据实体的ID进行缓存,缓存的是一个一个的对象
- 查询缓存:根据HQL查询语句进行缓存,缓存的是结果集。setCacheable(true)
缓存:是很多个map(key, value)组成,使用region来区别
-
ehcache使用
1.引入ehcache的相关jar包
ehcache-2.10.3.jar hibernate-ehcache-5.3.8.Final.jar slf4j-api-1.7.7.jar
- 编写ehcache.xml配置文件
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> <diskStore path="../ehcache/hibernate"/> <defaultCache maxElement