Mybatis为了方便我们扩展缓存定义了一个Cache接口,看看ehcache-mybatis的源码就明白了。我们要使用自己的cache同样的实现Cache接口即可
<cache type="cn.mgr.cache.RedisLoggingCache"/>
public class RedisCache implements Cache {
private static Log logger = LogFactory.getLog(RedisCache.class);
private Jedis redisClient = createClient();
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
private String id;
}
import org.apache.ibatis.cache.decorators.LoggingCache;
public class RedisLoggingCache extends LoggingCache {
public RedisLoggingCache(String id){
super(new RedisCache(id));
}
}