mybatis secondary cache extension - integration with redis

 

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));
 }
}

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326452500&siteId=291194637