学无先后,达者为师

网站首页 编程语言 正文

在Mybatis中使用自定义缓存ehcache

作者:weixin_44953227 更新时间: 2022-04-09 编程语言

自定义缓存 - ehcache

Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器

  1. 导包

<dependency>
    <groupId>org.mybatis.cachesgroupId>
    <artifactId>mybatis-ehcacheartifactId>
    <version>1.1.0version>
dependency>
  1. 在 Mapper.xml 中指定使用 ehcache 缓存实现

<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
  1. 在resource中定义配置文件 ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">

    

    
    <diskStore path="./tempdir/Tmp_Ehcache"/>

    
    <defaultCache
        eternal="false"
        maxElementsInMemory="10000"
        overflowToDisk="false"
        diskPersistent="false"
        timeToIdleSeconds="1800"
        timeToLiveSeconds="259200"
        memoryStoreEvictionPolicy="LRU"/>
    
    <cache
        name="cloud_user"
        eternal="false"
        maxElementsInMemory="5000"
        overflowToDisk="false"
        diskPersistent="false"
        timeToIdleSeconds="1800"
        timeToLiveSeconds="1800"
        memoryStoreEvictionPolicy="LRU"/>

    
ehcache>

原文链接:https://blog.csdn.net/weixin_44953227/article/details/112801107

栏目分类
最近更新