Mybatis无缝集成Memcached分布式缓存系统

本文介绍如何在MyBatis中配置Memcached作为缓存实现,包括在pom.xml中添加依赖、配置memcached.properties文件及在mapper.xml中启用缓存。

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

一. 客户端配置

1. 在pom.xml中加入

<dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-memcached</artifactId>
    <version>1.0.0</version>
</dependency>

2. 在classpath目录下新建memcached.properties文件, 内容如下

#any string identifier
org.mybatis.caches.memcached.keyprefix=_mybatis_
#space separated list of ${host}:${port}
org.mybatis.caches.memcached.servers=101.201.152.172:11211
#Any class that implementsnet.spy.memcached.ConnectionFactory
org.mybatis.caches.memcached.connectionfactory=net.spy.memcached.DefaultConnectionFactory
#the number of seconds in 30 days	the expiration time (in seconds)
org.mybatis.caches.memcached.expiration=30	
#flag to enable/disable the async get
org.mybatis.caches.memcached.asyncget=false	
#the timeout when using async get
org.mybatis.caches.memcached.timeout=5	
#the timeout unit when using async get
org.mybatis.caches.memcached.timeoutunit=java.util.concurrent.TimeUnit.SECONDS	
#if true, objects will be GZIP compressed before putting them to Memcached
org.mybatis.caches.memcached.compression=false

3. 在mapper.xml中加入以下代码

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值