您的位置:首页 > 数据库 > Memcache

mybatis + memcache 配置

2020-02-01 21:19 856 查看

项目中用到Cache, 研究了一下,配置一下Memcached+mybatis.

英文URL:http://mybatis.github.io/memcached-cache/ 。引用了原作,谢谢。

 

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 压缩

     

 

 

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>

 

  • 点赞
  • 收藏
  • 分享
  • 文章举报
iteye_21253 发布了5 篇原创文章 · 获赞 0 · 访问量 333 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: