zoukankan      html  css  js  c++  java
  • mybatis整合ehcache

    知识点:mybatis整合encache缓存框架,缓存从数据库中,查询的数据,不使用mybatis自带的二级缓存

    补充:github上Mybatis Ehcache 适配器包说明地址:http://www.mybatis.org/ehcache-cache/index.html

    (1)向pom.xm中导入缓存依赖包,和适配器包

    <!--ehcache依赖-->
    <dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    </dependency>

    <!--Mybatis Ehcache 适配器包-->
    <dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-ehcache</artifactId>
    <version>1.1.0</version>
    </dependency>

    (2)向mapper.xml中,添加配置
    <cache type="org.mybatis.caches.ehcache.EhcacheCache"></cache> //调用Mybatis Ehcache 适配器包中的接口,实现缓存功能
    //补充:其他mapper.xml中,再次使用缓存,直接使用
    <!--引用缓存,namespace:指定和哪个名称空间下的缓存一样-->
    <cache-ref namespace="com.xxMapper"></cache-ref>
    <!--<cache eviction="FIFO" flushInterval="60000" readOnly="false" size="1024"></cache>-->//区别mybatis自带的二级缓存配置


    (3)加入ehcache.xml配置文件
    <?xml version="1.0" encoding="UTF-8"?>
    <ehcache updateCheck="true" monitoring="autodetect" dynamicConfig="true">

    <!-- name:缓存名称
    eternal:缓存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期。
    maxElementsInMemory:内存缓存最大个数
    maxEntriesLocalDisk:当maxElementsInMemory已达到最大值时,写入磁盘
    timeToIdleSeconds:缓存对象失效前的闲置时间 默认值为:0 闲置时间无穷大
    timeToLiveSeconds:缓存对象最大的有效时间(TTL) 默认值为:0 闲置时间无穷大
    diskExpiryThreadIntervalSeconds::磁盘失效线程运行时间间隔,默认是120
    memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。
    默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)
    clearOnFlush:内存数量最大时是否清除
    -->

    <!-- 磁盘缓存位置 -->
        <diskStore path="E:/nishuai/cache"/>

    <!-- 默认缓存 -->
    <defaultCache
    maxEntriesLocalHeap="10000"
    eternal="false"
    timeToIdleSeconds="120"
    timeToLiveSeconds="120"
    maxEntriesLocalDisk="10000000"
    diskExpiryThreadIntervalSeconds="120"
    memoryStoreEvictionPolicy="LRU"/>

    </ehcache>
     
     
     
  • 相关阅读:
    android 微信(5.3)聊天UI的布局思考
    android 屏幕适配
    不同Activity之间的动画切换
    Freemarker 进行字符串截取
    如何使带背景图片的Button按钮中的文字居中偏上显示
    关于在IE-8下 button的背景图片不能正确显示的问题
    android Xmpp+openfire 消息推送 :SASL authentication failed using mechanism DIGEST-MD5
    Android运行出现“java.io.IOException: 您的主机中的软件放弃了一个已建立的连接。”
    计算机网络
    Java基础-3
  • 原文地址:https://www.cnblogs.com/shuaifing/p/9283750.html
Copyright © 2011-2022 走看看