iBATIS中使用EHCache
    需要实现CacheController接口并通过一系列的配置委托iBATIS使用EHCache进行缓存.
- 
package com.ibatis.sqlmap.engine.cache.EhCacheController; 
- 
import java.net.URL; 
- 
import java.util.Properties; 
- 
import net.sf.ehcache.Cache; 
- 
import net.sf.ehcache.CacheManager; 
- 
import net.sf.ehcache.Element; 
- 
import com.ibatis.sqlmap.engine.cache.CacheController; 
- 
import com.ibatis.sqlmap.engine.cache.CacheModel; 
- 
 
- 
* EhCache Implementation of the {@link com.ibatis.sqlmap.engine.cache.CacheController} interface to be able to use 
- 
* EhCache as a cache implementation in iBatis. You can configure your cache model as follows, by example, in your 
- 
* sqlMapping files: 
- 
* <cacheModel id="myCache" type="nl.rabobank.springproject.ibatis.EhCacheController" readOnly="true" serialize="false"> 
- 
*??? <property name="configFile" value="/path-to-ehcache.xml"/> 
- 
* </cacheModel> 
- 
* Alternatively, you can use a type alias in your type attribute and defining the class with a 
- 
* <TypeAlias> declaration, see iBatis documentation on how to do this. 
- 
*/ 
- 
public class EhCacheController implements CacheController { 
- 
???? 
- 
????private CacheManager cacheManager; 
- 
???? 
- 
????? * Flush a cache model. 
- 
????? * @param cacheModel - the model to flush. 
- 
????? */ 
- 
????public void flush(CacheModel cacheModel) { 
- 
???????? getCache(cacheModel).removeAll(); 
- 
???? } 
- 
???? 
- 
????? * Get an object from a cache model. 
- 
????? * @param cacheModel - the model. 
- 
????? * @param key???????? - the key to the object. 
- 
????? * @return the object if in the cache, or null(?). 
- 
????? */ 
- 
????public Object getObject(CacheModel cacheModel, Object key) { 
- 
???????? Object result = null; 
- 
???????? Element element = getCache(cacheModel).get(key); 
- 
????????if (element != null) { 
- 
???????????? result = element.getObjectValue(); 
- 
???????? } 
- 
????????
 
                    
                    
                        免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。