首页 > 系统服务 > 详细

MyBatis Review——整合ehcache

时间:2016-05-27 12:23:46      阅读:127      评论:0      收藏:0      [点我收藏+]


     ehcache是一个分布式缓存框架,是hibernate中二级缓存的默认实现。


    一,整合的思路


      mybatis提供了一个cache接口,如果要实现自己的缓存逻辑,实现cache接口开发即可:


        技术分享


    mybatis和ehcache整合:mybatis和ehcache的整合包中提供了一个cache接口的实现类:


    技术分享


1,加入jar


技术分享


2,整合ehcache

           mapper.xml中配置:

 

<!-- 
		type:指定cache接口的实现类的类型,mybatis默认使用PertualCache和Cache整合,
		需要配置type为org.mybatis.caches.ehcache.EhcacheCache
		来实现Cache接口
	 -->
	<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>


3,加入ehcache.xml配置文件


<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
	<diskStore path="H:\ehcache" />
	<defaultCache 
		maxElementsInMemory="1000" 
		maxElementsOnDisk="10000000"
		eternal="false" 
		overflowToDisk="false" 
		timeToIdleSeconds="120"
		timeToLiveSeconds="120" 
		diskExpiryThreadIntervalSeconds="120"
		memoryStoreEvictionPolicy="LRU">
	</defaultCache>
</ehcache>



ok~



MyBatis Review——整合ehcache

原文:http://blog.csdn.net/lhc1105/article/details/51493387

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!