mybatis + memcache 配置

本文介绍如何在MyBatis项目中集成Memcached作为缓存解决方案,包括配置pom.xml依赖、设置缓存参数及在mapper文件中启用缓存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中用到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 配置的,如果没有使用默认

 

PropertyDefaultDescription
org.mybatis.caches.memcached.keyprefix_mybatis_缓存key的前缀
org.mybatis.caches.memcached.serverslocalhost: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.asyncgetfalse是否启用异步读
org.mybatis.caches.memcached.timeout5使用异步读的timeout时间
org.mybatis.caches.memcached.timeoutunit

java.util.concurrent.

TimeUnit.SECONDS

timeout单位
org.mybatis.caches.memcached.compressionfalse

如果开启,对象在放到

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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值