mybatis整合memcache
mybatis官方出了對memcache的整合,使mybatis也可以使用分布式緩存,除了memcache外還有個Hazelcast的整合包。
We have just released the 1st GA version of the MyBatis Memcached adapter.
The beta has bee around for almost one year and only one issue was reported.
這個memcache的整合是官方發布的版本,在網上找了找都沒看到相關介紹,我這次也當次搬運工
pom文件引用
<dependency> <groupId>org.mybatis.caches</groupId> <artifactId>mybatis-memcached</artifactId> <version>1.0.0</version> </dependency>
也可以上github上下載https://github.com/mybatis/memcached-cache/releases
http://mybatis.github.io/memcached-cache/ 這個是說明
在mapper中配置
<mapper namespace="org.acme.FooMapper"> <cache type="org.mybatis.caches.memcached.MemcachedCache" /> ... </mapper>
memcache的配置是根據classpath下的 /memcached.properties 配置的,如果沒有使用默認
Property | Default | Description |
org.mybatis.caches.memcached.keyprefix | _mybatis_ | 緩存key的前綴 |
org.mybatis.caches.memcached.servers | localhost:11211 | memcache配置${host}:${port} |
org.mybatis.caches.memcached.connectionfactory | net.spy.memcached.DefaultConnectionFactory | 只要是實現接口net.spy.memcached.ConnectionFactory |
org.mybatis.caches.memcached.expiration | 過期時間 |
單位是秒 |
org.mybatis.caches.memcached.asyncget | false | 是否啟用異步讀 |
org.mybatis.caches.memcached.timeout | 5 | 使用異步讀的timeout時間 |
org.mybatis.caches.memcached.timeoutunit | java.util.concurrent.TimeUnit.SECONDS | timeout單位 |
org.mybatis.caches.memcached.compression | false | 如果開啟,對象在放到memcache前會使用GZIP 壓縮 |