`
louisgarcia
  • 浏览: 4815 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

二级缓存

阅读更多
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     <property name="dataSouce" ref="dataSource"/>
     <property name="mappingResources">
           <list>
             <value></value>
           </list>
     </property>
     <property name="hibernateProperties">
         <value>
          hibernate.dialect=org.hibernate.dialect.SQLServerDialect
          hibernate.hbm2ddl.auto=update
          hibernate.show_sql=false
          hibernate.format_sql=false
          hibernate.cache.use.second_level_cache=true
          hibernate.cache.use_query_cache=false
          hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
         </value>
     </property>
  </bean>

定义二级缓存
   hibernate.cache.use.second_level_cache=true 使用二级缓存
   hibernate.cache.use_query_cache=false        使用查询缓存
   hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider



配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!--
     defaultCache节点为缺省的缓存策略
     maxElementsInMemory 内存中最大允许存在的对象数量
     eternal 设置缓存中的对象是否永远不过期
     overflowToDisk 把溢出的对象存放到硬盘上
     timeToIdleSeconds 指定缓存对象空闲多长时间就过期,过期的对象会被清除掉
     timeToLiveSeconds 指定缓存对象总的存活时间
     diskPersistent 当jvm结束是是否持久化对象
     diskExpiryThreadIntervalSeconds 指定专门用于清除过期对象的监听线程的轮询时间
-->
<ehcache>
    <diskStore path="D:\cache"/>
    <defaultCache  maxElementsInMemory="1000" eternal="false" overflowToDisk="true"
        timeToIdleSeconds="120"
        timeToLiveSeconds="180"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="60"/>

  <!--设定缓存对象区域-->
    <cache name="com.hx.ssh.bean.Login" maxElementsInMemory="100" eternal="false"
    overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="600" diskPersistent="false"/>
</ehcache>



其中,person的hibernate配置文件如下:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.hx.ssh.bean.Login" table="login">
     <cache usage="read-write" region="com.hx.ssh.bean.Login"/>
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="native"></generator>
        </id>
        <property name="name" type="java.lang.String">
            <column name="name" length="100" />
        </property>
    </class>
</hibernate-mapping>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics