1、 Memcache和Mybatis整合jar 下载:
mybatis-memcached-1.0.0.jar
maven项目添加:
<!-- mybatis整合memcache --> <dependency> <groupId>org.mybatis.caches</groupId> <artifactId>mybatis-memcached</artifactId> <version>1.0.0</version> </dependency>
2、Mapper文件添加如下语句:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="com.xxx.dao.xxx" > <cache type="org.mybatis.caches.memcached.LoggingMemcachedCache" /> <resultMap id="xxx" type="com.xxx.xxx.xxx" > <id column="ID" property="id" jdbcType="BIGINT" /> </resultMap>
配置方式分为有日志和无日志两种:
无日志
<cache type="org.mybatis.caches.memcached.MemcachedCache" />
有日志
<cache type="org.mybatis.caches.memcached.LoggingMemcachedCache" />
3、classpath下新建memcached.properties文件,格式如下:
#any string identifier
org.mybatis.caches.memcached.keyprefix=_biz-cache-wk_
#space separated list of ${host}:${port}
org.mybatis.caches.memcached.servers=192.168.0.200:12000
#org.mybatis.caches.memcached.servers=192.168.0.44:12000
#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=6000
#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
org.mybatis.caches.memcached.compression=false
#\u7f13\u5b58\u670d\u52a1\u5668\u5b95\u673a\u540e\u591a\u4e45\u4e0d\u4f7f\u7528memcached \u6beb\u79d2\u4e3a\u5355\u4f4d
#refuse time when connection refused
org.mybatis.caches.memcached.refuseperiod=1000
配置参数说明:
Property | Default | Description |
org.mybatis.caches.memcached.keyprefix | _mybatis_ | 缓存key的前缀 |
org.mybatis.caches.memcached.servers | localhost:11211 | memcache地址 |
org.mybatis.caches.memcached.connectionfactory | net.spy.memcached.DefaultConnectionFactory | 只要实现接口net.spy.memcached.ConnectionFactory |
org.mybatis.caches.memcached.expiration | 2592000(30天的秒数) | 过期时间单位秒 |
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 压缩 |
相关推荐
项目使用Spring4+SpringMVC+mysql【同时支持mybatis+hibernate两种底层操作框架】+memcached
文档介绍了 1.使用simple-spring-memcached 3.0.2集成memcached和spring; 2.mybatis-memcached-1.0.0-beta1-bundle的用法。
使用Spring,SpringMVC,mybatis框架 将memcached和Spring集成,基于Spring原Cache注解
使用Spring Boot进行Memcached为什么要使用Memcached?您是否正在为每个事务与数据库进行交互? 然后,您必须应用缓存机制,以避免多次数据库调用和更快的响应。一个免费的开源内存中缓存系统,可通过减少数据库负载...
spring 实践学习案例,与其它组件结合如 mybatis、jpa、dubbo、redis、mongodb、memcached、kafka、rabbitmq、activemq、shiro等 #### 软件架构 基于Java 1.8 #### Spring 版本 - 5.0.8.RELEASE #### 模块说明 - ...
spring boot 实践学习案例,与其它组件结合如 mybatis、jpa、dubbo、redis、mongodb、memcached、kafka、rabbitmq、activemq、elasticsearch、security、shiro等 #### Spring Boot 版本 - 2.0.3.RELEASE #### 模块...
redis集成 mybatis缓存实现和redis session共享问题,详细代码。 结合项目中优点: (1) 因为数据存在内存中,类似于 HashMap ,HashMap 的优势就是查找和操作的时间复杂度都是O (1) 。 (2) Redis 本质上是一个 Key-...
[Spring Boot:使用Memcached缓存] [Spring Boot:使用Redis存储技术] [Spring Boot:使用Rabbit MQ消息队列] [Spring Boot:整合JdbcTemplate] [Spring Boot:整合Spring Data JPA] [Spring Boot:整合MyBatis框架]...
一直在金融行业里做软件项目,见识了各种形形色色的企业软件开发框架,由于金融行业...3、Hibernate和Mybatis的集成,DB的事务管理由Hibernate提供支持,所以一般增删改的操作由Hibernate来完成,而查询则交由Mybatis。
同时,集成了MyBatis作为持久层框架,实现了数据库操作和数据访问的解耦。功能模块:本系统包括以下核心功能模块:用户管理模块:支持用户注册、登录、修改个人信息等功能。图书管理模块:提供图书的添加、编辑、...
│ 第10节:Spring+Mybatis实现DAO.avi │ 第11节:Mybatis的分页实现.avi │ 第12节:Service的实现以及模块化.avi │ 第13节:Spring MVC实现Web层开发.avi │ 第14节:新增和列表页面和分页tag.avi │ 第15节:带...