Mybatis defines a Cache interface in order to facilitate us to extend the cache. Just look at the source code of ehcache-mybatis to understand. We need to use our own cache to implement the same Cache interface.
<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));
}
}