zoukankan      html  css  js  c++  java
  • hibernate缓存

    memcache 服务器缓存, ehcache服务器缓存

    使用ehcache

      导入jar 包

      添加ehcache.xml

      设置二级缓存

    ehcache.xml  
    
    <ehcache>     
        <diskStore path="java.io.tmpdir"/>     
        <defaultCache     
            maxElementsInMemory=“10000“ →缓存中最大允许保存的对象数量     
            eternal=“false“  →缓存中数据是否为常量     
            timeToIdleSeconds=“120“  →缓存数据钝化时间 ,单位为秒     
            timeToLiveSeconds=“120“  →缓存数据生存时间 ,单位为秒     
            overflowToDisk=“true“  →内存不足时 ,是否启用磁盘缓存     
            />     
    </ehcache>  
      
    hibernate.cfg.xml
    <!-- 开启二级缓存 -->
            <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
    teacher.hbm.xml
    <class name="Teacher" table="t_teacher">
            <cache usage="read-only"/>
            <id name="id" column="id">
            ........
        </class>

    EHCache支持以下三种同步策略 :

    read-only :只读。对于不会发生改变的数据 ,可以使用只读性缓存。
    read-write :可读写缓存。用于对数据同步要求严格的情况。
    nonstrict-read-write :如果程序对并发访问下的数据同步要求不是很严格 ,且数据更新操作不频繁时可采用该缓存策略


  • 相关阅读:
    mysql实战45讲
    goland破解
    主从复制系列C
    主从复制系列B
    主从复制系列A
    sshd配置文件详解
    MySQL源码 数据结构array
    MySQL源码 information_schema新增表
    MySQL5.6 基于db的并行复制
    mysql 限制并发select patch
  • 原文地址:https://www.cnblogs.com/fudapeng/p/3858652.html
Copyright © 2011-2022 走看看