Hibernate4.x二级缓存详细配置步骤( EHCache)
2012-09-11 21:31
225 查看
Hibernate4.x : 二级缓存的详细配置: EHCache
Hibernate4.x中使用缓存的步骤为(EHCache);
1. 将相应的二级缓存组件jar包导入到classpath类路径下
2.在hibernate.cfg.xml文件中配置如下的信息:
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
3. 指定哪些对象选要被缓存:这里既可以在hibernate.cfg.xml文件中配置,也可以在对应的hbm文件中配置
1) hibernate.cfg.xml文件中配置如下:
指定需要缓存的对象类型:这里可以在映射文件中配置,也可以在hibernate核心配置文件中进行配置
<class-cache class="com.hib.entity.Inf" usage="read-only" />
2) hbm文件中配置如下:
<cache usage="read-only"/> 在需要缓存的元素下添加<cache>元素,根据需求使用相应的缓存级别
4. 在src目录下编写一个ehcache.xml文件,配置一些基本的缓存信息:
一般配置信息如下:
<?xml version="1.0" encoding="utf-8"?>
<ehcache>
<diskStore path="D:/ehcache"/><!--如果缓存中的对象存储超过指定的缓存数量的对象存储的磁盘地址-->
<!--全部默认的配置
maxElementsInMemory在內存中最多存放多少个对象
eternal对象是不是永远不变的,一般都是false
timeToLiveSeconds如果这个对象超过了这个时间,就会从缓存中清除
-->
<defaultCache
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<!-- 针对指定的对象使用的缓存配置
name表示的是缓存的类对象的全路径名 -->
<cache name="com.hibernate.Student"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="50"
timeToLiveSeconds="50"
overflowToDisk="true"
/>
</ehcache>
Hibernate4.x中使用缓存的步骤为(EHCache);
1. 将相应的二级缓存组件jar包导入到classpath类路径下
2.在hibernate.cfg.xml文件中配置如下的信息:
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
3. 指定哪些对象选要被缓存:这里既可以在hibernate.cfg.xml文件中配置,也可以在对应的hbm文件中配置
1) hibernate.cfg.xml文件中配置如下:
指定需要缓存的对象类型:这里可以在映射文件中配置,也可以在hibernate核心配置文件中进行配置
<class-cache class="com.hib.entity.Inf" usage="read-only" />
2) hbm文件中配置如下:
<cache usage="read-only"/> 在需要缓存的元素下添加<cache>元素,根据需求使用相应的缓存级别
4. 在src目录下编写一个ehcache.xml文件,配置一些基本的缓存信息:
一般配置信息如下:
<?xml version="1.0" encoding="utf-8"?>
<ehcache>
<diskStore path="D:/ehcache"/><!--如果缓存中的对象存储超过指定的缓存数量的对象存储的磁盘地址-->
<!--全部默认的配置
maxElementsInMemory在內存中最多存放多少个对象
eternal对象是不是永远不变的,一般都是false
timeToLiveSeconds如果这个对象超过了这个时间,就会从缓存中清除
-->
<defaultCache
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<!-- 针对指定的对象使用的缓存配置
name表示的是缓存的类对象的全路径名 -->
<cache name="com.hibernate.Student"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="50"
timeToLiveSeconds="50"
overflowToDisk="true"
/>
</ehcache>
相关文章推荐
- Hibernate4.1.4配置二级缓存EHCache步骤
- Hibernate4.1.4配置二级缓存EHCache步骤
- Hibernate4.1.4配置二级缓存EHCache步骤
- 二级缓存EhCache在几种应用技术的配置方法和步骤总结
- Hibernate配置EHCache二级缓存的步骤
- Hibernate 的 二级缓存——ehcache配置文件
- 利用Spring的AOP来配置和管理你的二级缓存(EHCache)
- 配置二级缓存的主要步骤:
- 利用Spring的AOP来配置和管理你的二级缓存(EHCache)
- Hibernate 4.2.4配置二级缓存的步骤
- HIbernate 中配置二级缓存Ehcache ,C3p0连接池,反向创建数据库
- Hibernate二级缓存以及ehcache的搭建配置
- MyBatis--查询缓存--ehcache二级缓存配置
- 利用Spring的AOP来配置和管理你的二级缓存(EHCache)
- hibernate配置二级缓存基本步骤
- Hibernate EhCache 二级缓存配置.pdf
- hibernate二级缓存 Ehcache配置详解
- ehcache缓存的详细配置
- spring二级缓存的ehcache 的 配置文件
- 利用Spring的AOP来配置和管理你的二级缓存(EHCache) 记录以备查询