hibernate 二级缓存 个人总结

今天特地的回顾了一下hibernate 的二级缓存, 我平常用到的是两种
1:   ehcache 
    1.1 首先配置 ehcache.xml  当然也可以默认 也可以自定义
Java代码 复制代码
  1. "Student"  
  2.         maxElementsInMemory="80" eternal="false" overflowToDisk="false"  
  3.         timeToIdleSeconds="80" timeToLiveSeconds="80"   />   

     说明: name 就是自定义的名称   
             maxElementsInMemory   缓存存储的总记录量
             eternal  缓存是否永远不销毁
             overflowToDisk  当缓存到达总数后是否覆盖原来的
             timeToIdleSeconds   当缓存空闲时间超过该值 则缓存自动销毁 感觉上没多大用处 可能是测试的时候 缓存量的问题
             timeToLiveSeconds 缓存创建之后,到达该缓存自动销毁 同上
    1.2 让后在用到的 hibernate映射文件中 添加
Java代码 复制代码
  1.   
  2.     <class name="com.eagle.model.cache.Student" table="t_student" >   
  3.       [u]"read-write" region="Student"  />[/u]      
  4.         ………省略 ……………    class>   
  5.   
      [u][/u]   
        ………省略 ……………    

   表示该类要用缓存   另 可以在 hibernate.cfg.xml 添加
Java代码 复制代码
  1. <class-cache class="com.eagle.model.cache.Student"  
  2.             usage="read-write" region="Student" />  
  可以在hibernate.cfg.xml 统一管理那里类用到了缓存 
说明  region  指定使用哪个缓存机制。这个在ehcache 中所配置的
       usage   这个是必须的  缓存的策略: transactional、 read-write、 nonstrict-read-write或 read-only。
    1.3    在hibernate.cfg.xml 数据连接池 别忘记加上
   
Java代码 复制代码
  1. "hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider   
  2.            
  3.         "hibernate.cache.use_second_level_cache">true  
org.hibernate.cache.EhCacheProvidertrue



2 如果 你用的是 org.hibernate.cache.HashtableCacheProvider 
   就只需要在需要用的hibernate映射文件中 添加 当然这个也可以跟 上面的一样可以统一在配置文件中管理起来 。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22893636/viewspace-630943/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22893636/viewspace-630943/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值