mybatis-memcached框架配置

官方放出了mybatis和memcached的整合包,先附上官方文档地址
文档很简洁,事实证明使用起来也很简单
memcached的安装我这里就不再讲了,网上很容易找到
在项目中引入
<dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-memcached</artifactId>
    <version>1.0.0</version>
  </dependency>
然后在想使用的mapper中加入
<mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.memcached.MemcachedCache" />
  ...
</mapper>
就可以用了

再建一个memcached.properties,对他进行配置
Property Default Description
org.mybatis.caches.memcached.keyprefix _mybatis_ any string identifier
org.mybatis.caches.memcached.servers localhost:11211 space separated list of ${host}:${port}
org.mybatis.caches.memcached.connectionfactory net.spy.memcached.DefaultConnectionFactory Any class that implementsnet.spy.memcached.ConnectionFactory
org.mybatis.caches.memcached.expiration the number of seconds in 30 days the expiration time (in seconds)
org.mybatis.caches.memcached.asyncget false flag to enable/disable the async get
org.mybatis.caches.memcached.timeout 5 the timeout when using async get
org.mybatis.caches.memcached.timeoutunit java.util.concurrent.TimeUnit.SECONDS the timeout unit when using async get
org.mybatis.caches.memcached.compression false if true, objects will be GZIP compressed before putting them to Memcached
我简单测试了一下发现它可以配置多个服务器,用逗号分隔,经测试如果某一台挂掉,他会选择正常的那台
如果2台都挂掉,就会报错,估计我们还是希望在memcached服务器挂掉后从数据库读取数据,不知道大家有什么好的实现方式或者思路吗
org.mybatis.caches.memcached.servers=172.29.33.201:11211,localhost:11211
org.mybatis.caches.memcached.expiration=30 
org.mybatis.caches.memcached.asyncget=false 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值