本文主要是介绍Mybatis与ehcache缓存框架整合,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1 分布式缓存
目的:将缓存数据进行分布式的管理
作用:通过mybatis和ehcache整合,可以把缓存数据的管理托管ehcache
在mybatis中提供一个cache接口,只要实现cache接口就可以把缓存数据灵活的管理起来。
2 整合步骤
下载jar包
配置ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"><!--diskStore:缓存数据持久化的目录 地址 --><diskStore path="F:\develop\ehcache" /><defaultCache maxElementsInMemory="1000" maxElementsOnDisk="10000000"eternal="false" overflowToDisk="false" diskPersistent="true"timeToIdleSeconds="120"timeToLiveSeconds="120" diskExpiryThreadIntervalSeconds="120"memoryStoreEvictionPolicy="LRU"></defaultCache>
</ehcache>
Mapper中使用ehcache的缓存
也可以实现个性化配置
这篇关于Mybatis与ehcache缓存框架整合的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!