一. 客户端配置
1. 在pom.xml中加入
<dependency>
<groupId>org.mybatis.caches</groupId>
<artifactId>mybatis-memcached</artifactId>
<version>1.0.0</version>
</dependency>
2. 在classpath目录下新建memcached.properties文件, 内容如下
#any string identifier
org.mybatis.caches.memcached.keyprefix=_mybatis_
#space separated list of ${host}:${port}
org.mybatis.caches.memcached.servers=101.201.152.172:11211
#Any class that implementsnet.spy.memcached.ConnectionFactory
org.mybatis.caches.memcached.connectionfactory=net.spy.memcached.DefaultConnectionFactory
#the number of seconds in 30 days the expiration time (in seconds)
org.mybatis.caches.memcached.expiration=30
#flag to enable/disable the async get
org.mybatis.caches.memcached.asyncget=false
#the timeout when using async get
org.mybatis.caches.memcached.timeout=5
#the timeout unit when using async get
org.mybatis.caches.memcached.timeoutunit=java.util.concurrent.TimeUnit.SECONDS
#if true, objects will be GZIP compressed before putting them to Memcached
org.mybatis.caches.memcached.compression=false
3. 在mapper.xml中加入以下代码
<mapper namespace="org.acme.FooMapper">
<cache type="org.mybatis.caches.memcached.MemcachedCache" />
...
</mapper>