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>
     
     
     
  • 相关阅读:
    Java基础——Instanceof 运算符
    算法——八皇后问题(eight queen puzzle)之回溯法求解
    浅析数据结构
    react給變量賦值并列元素
    如何使用npm构建一个react demo项目
    Java面试题 静态代码块 构造代码块 构造方法 的执行顺序
    Mysql 反向解析 导致远程访问慢
    Django admin管理工具
    Django-Ajax(85)
    jQuery快速入门
  • 原文地址:https://www.cnblogs.com/shuaifing/p/9283750.html
Copyright © 2011-2022 走看看