springBoot项目mybatis中加入缓存

1:maven:

 <!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.6.11</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis.caches</groupId>
            <artifactId>mybatis-ehcache</artifactId>
            <version>1.1.0</version>
</dependency>

2:在基础数据的xml文件中加入配置:

<!--添加缓存配置-->
    <cache type="org.mybatis.caches.ehcache.EhcacheCache">
        <property name="timeToIdleSeconds" value="60"></property><!--&lt;!&ndash;当缓存闲置60秒后销毁&ndash;&gt;-->
        <property name="timeToLiveSeconds" value="160"></property><!--&lt;!&ndash;缓存存在160秒后销毁&ndash;&gt;-->
        <property name="maxEntriesLocalHeap" value="1000"></property>
        <property name="maxEntriesLocalDisk" value="10000000"></property>
        <property name="memoryStoreEvictionPolicy" value="LRU"></property>
    </cache>
posted @ 2019-08-22 14:36  生活无限美  阅读(1259)  评论(0编辑  收藏  举报