Ehcache是一个开源Java分布式缓存。可以配合mybatis来使用
 
首先,在资源文件夹中新建ehcache.xml
ehcache 一二事 - ssm 中ehcashe的简单配置应用
 
内容如下:
 1 <?xml version="1.0" encoding="UTF-8"?>  
 2 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
 3     xsi:noNamespaceSchemaLocation="../bin/ehcache.xsd">  
 4     <defaultCache overflowToDisk="true" eternal="false" maxElementsInMemory="1"/>  
 5     <!-- 在生产环境中需要修改路径地址 -->
 6     <!-- dev -->
 7     <diskStore path="D:/cache" />
 8     <!-- product linux -->
 9 <!--     <diskStore path="XXX" />   -->
10 </ehcache>  

在自己的model中必须序列化,序列化ID必须自动生成(在redis中也是这么做的)

ehcache 一二事 - ssm 中ehcashe的简单配置应用

在mapper.xml中加入以下ehcache:

1     <!-- 输出日志 -->
2 <!--     <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
3     <!-- 不输出日志 -->
4     <cache type="org.mybatis.caches.ehcache.EhcacheCache"/>

select表情中的useCache默认是true,会使用cache,如果不需要,设置为false就行

ehcache 一二事 - ssm 中ehcashe的简单配置应用

 

经测试,第一次查询会有sql的输出,第二次开始的同样查询则没有

ehcache 一二事 - ssm 中ehcashe的简单配置应用

硬盘上的缓存文件

ehcache 一二事 - ssm 中ehcashe的简单配置应用

 

 

 

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-10-01
  • 2021-07-15
猜你喜欢
  • 2022-02-03
  • 2021-08-14
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-07-16
相关资源
相似解决方案