mybatis整合memcache

jopen 10年前發布 | 52K 次閱讀 MyBatis3 持久層框架 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 配置的,如果沒有使用默認

</tr>

</tbody> </table>

If users need to log cache operations, they can plug the Cache logging version:

<mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.memcached.LoggingMemcachedCache" />
  ...
</mapper>

還沒看代碼是怎么實現的,是不是可以實現那種hibernate的二級緩存功能

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
Property DefaultDescription
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 壓縮



  • sesese色