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 :如果程序对并发访问下的数据同步要求不是很严格 ,且数据更新操作不频繁时可采用该缓存策略


  • 相关阅读:
    Python服务Debian打包新思路
    小议Python3的原生协程机制
    推送公司今日菜单内容到手机
    Python包管理工具小结
    PAT 1068. 万绿丛中一点红
    PAT 1067. 试密码
    PAT 1066. 图像过滤
    PAT 1065. 单身狗
    PAT 1064. 朋友数
    PAT 1063. 计算谱半径
  • 原文地址:https://www.cnblogs.com/fudapeng/p/3858652.html
Copyright © 2011-2022 走看看