springboot 集成J2Cache
J2Cache 是 OSChina 目前正在使用的两级缓存框架。第一级缓存使用 Ehcache,第二级缓存使用 Redis 。由于大量的缓存读取会导致 L2 的网络成为整个系统的瓶颈,因此 L1 的目标是降低对 L2 的读取次数。该缓存框架主要用于集群环境中。单机也可使用,用于避免应用重启导致的 Ehcache 缓存数据丢失。
j2Cache提供了springboot 的集成。
集成方法如下:
1.引入pom.xml
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-spring-boot2-starter</artifactId>
<version>2.7.6-release</version>
</dependency> <dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId>
<version>2.7.7-release</version>
</dependency>
2.增加配置文件

ehcache3.xml
<!-- for ehcache 3.x -->
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd"> <!-- Don't remote default cache configuration -->
<cache-template name="default">
<key-type>java.lang.String</key-type>
<value-type>java.io.Serializable</value-type>
<expiry>
<ttl unit="seconds">1800</ttl>
</expiry>
<resources>
<heap>1000</heap>
<offheap unit="MB">100</offheap>
</resources> </cache-template>
<!--
<persistence directory="${ecache.path}"/>
-->
<cache alias="default" uses-template="default"/> </config>
j2cache.properties
#J2Cache configuration #########################################
# Cache Broadcast Method
# values:
# jgroups -> use jgroups's multicast
# redis -> use redis publish/subscribe mechanism
######################################### j2cache.broadcast = net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy # 是否开启二级缓存
j2cache.l2-cache-open=true
j2cache.open-spring-cache= true
j2cache.allow-null-values= true
j2cache.cache-clean-mode= active
j2cache.redis-client=jedis #组播的通道名称
jgroups.channel.name = j2cache #########################################
# Level 1&2 provider
# values:
# none -> disable this level cache
# ehcache -> use ehcache2 as level 1 cache
# ehcache3 -> use ehcache3 as level 1 cache
# caffeine -> use caffeine as level 1 cache(only in memory)
# redis -> use redis(hashs) as level 2 cache
# [classname] -> use custom provider
######################################### j2cache.L1.provider_class = ehcache3
j2cache.L2.provider_class = net.oschina.j2cache.cache.support.redis.SpringRedisProvider
#j2cache.L2.provider_class = redis
j2cache.L2.config_section = redis
#j2cache.L2.provider_class = redis #########################################
# Cache Serialization Provider
# values:
# fst -> fast-serialization
# kyro -> kyro
# java -> java standard
# [classname implements Serializer]
######################################### j2cache.serialization = fst #########################################
# Ehcache configuration
######################################### #ehcache.name=
#ehcache.configXml=/ehcache.xml
ehcache3.configXml = /config/ehcache3.xml #########################################
# Caffeine configuration
# caffeine.region.[name] = size, xxxx[s|m|h|d]
#
######################################### caffeine.region.default = 1000, 1h #########################################
# Redis connection configuration
######################################### #########################################
# Redis Cluster Mode
#
# single -> single redis server
# sentinel -> master-slaves servers
# cluster -> cluster servers (数据库配置无效,使用 database = 0)
# sharded -> sharded servers (密码、数据库必须在 hosts 中指定,且连接池配置无效 ; redis://user:password@127.0.0.1:6379/0)
#
######################################### #redis.mode = sentinel
redis.mode = single
#cluster name just for sharded
redis.cluster_name = mymaster ## redis cache namespace optional, default[j2cache]
redis.namespace = j2cache ## connection
#redis.hosts = 127.0.0.1:26378,127.0.0.1:26379,127.0.0.1:26380
redis.hosts = 192.168.1.100:6379
redis.timeout = 2000
redis.password =
#redis.database = 0 ## redis pub/sub channel name
redis.channel = j2cache ## redis pool properties
redis.maxTotal = -1
redis.maxIdle = 2000
redis.maxWaitMillis = 100
redis.minEvictableIdleTimeMillis = 864000000
redis.minIdle = 1000
redis.numTestsPerEvictionRun = 10
redis.lifo = false
redis.softMinEvictableIdleTimeMillis = 10
redis.testOnBorrow = true
redis.testOnReturn = false
redis.testWhileIdle = false
redis.timeBetweenEvictionRunsMillis = 300000
redis.blockWhenExhausted = true
redis.mode = single 模式支持 single,sentinel,cluster
redis.hosts:需要配置为redis的主机
j2cache.l2-cache-open:是否开启二级缓存
3.注入CacheChannel
@Component(value = "iCache")
public class J2cacheImpl implements ICache { private String region="rx"; @Autowired
private CacheChannel cacheChannel;
4.修改配置文件
application.properties
j2cache:
config-location: classpath:/config/j2cache.properties
配置j2cache.properties 文件路径
springboot 集成J2Cache的更多相关文章
- 【springBoot】springBoot集成redis的key,value序列化的相关问题
使用的是maven工程 springBoot集成redis默认使用的是注解,在官方文档中只需要2步; 1.在pom文件中引入即可 <dependency> <groupId>o ...
- SpringBoot集成security
本文就SpringBoot集成Security的使用步骤做出解释说明.
- springboot集成Actuator
Actuator监控端点,主要用来监控与管理. 原生端点主要分为三大类:应用配置类.度量指标类.操作控制类. 应用配置类:获取应用程序中加载的配置.环境变量.自动化配置报告等与SpringBoot应用 ...
- SpringBoot集成Shiro并用MongoDB做Session存储
之前项目鉴权一直使用的Shiro,那是在Spring MVC里面使用的比较多,而且都是用XML来配置,用Shiro来做权限控制相对比较简单而且成熟,而且我一直都把Shiro的session放在mong ...
- SpringBoot集成redis的key,value序列化的相关问题
使用的是maven工程 springBoot集成redis默认使用的是注解,在官方文档中只需要2步; 1.在pom文件中引入即可 <dependency> <groupId>o ...
- springboot集成mybatis(二)
上篇文章<springboot集成mybatis(一)>介绍了SpringBoot集成MyBatis注解版.本文还是使用上篇中的案例,咱们换个姿势来一遍^_^ 二.MyBatis配置版(X ...
- springboot集成mybatis(一)
MyBatis简介 MyBatis本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation迁移到了google code,并且改名为MyB ...
- springboot集成redis(mybatis、分布式session)
安装Redis请参考:<CentOS快速安装Redis> 一.springboot集成redis并实现DB与缓存同步 1.添加redis及数据库相关依赖(pom.xml) <depe ...
- SpringBoot集成jsp
一.springBoot集成jsp: 1.修改pom文件 <!--集成jsp所需jar包--> <!--jsp页面使用jstl标签--> <dependency> ...
随机推荐
- vue.config.js 配置 scss,less,sass全局配置 vuecli3
module.exports = { /* 部署生产环境和开发环境下的URL:可对当前环境进行区分,baseUrl 从 Vue CLI 3.3 起已弃用,要使用publicPath */ public ...
- JAVA程序执行顺序(静态代码块》非静态代码块》静态方法》构造函数)
总结:静态代码块总是最先执行. 非静态代码块跟非静态方法一样,跟对象有关.只不过非静态代码块在构造函数之前执行. 父类非静态代码块.构造函数执行完毕后(相当于父类对象初始化完成), 才开始执行子类的非 ...
- 【BigData】Java基础_HashMap
HashMap简介 HashMap是一种非常常见.方便和有用的集合,是一种键值对(K-V)形式的存储结构 常见的方法如下: put:将数据添加到集合中 get:获取集合中的元素 size:获取集合的长 ...
- 阿里云 API 签名机制的 Python 实现
在调用阿里云 API 的时候,最让人头疼的就是 API 的签名(Signature)机制,阿里云在通用文档中也有专项说明,但是仅仅有基于 Java 的实现代码示例.所以这里基于 Python 来分析下 ...
- FPGA硬件加速
FPGA市场占有率最高的两大公司Xilinx和Altera. 查找表(Look-Up-Table)简称为LUT,LUT本质上就是一个RAM.目前FPGA中多使用4输入的LUT,所以每一个LUT可以看成 ...
- 展示时测试Markdown渲染
\begin{equation} %公式 Speedup_{overall} = \frac{1}{{(1-Fraction_{partitioned})} +\frac{Fraction_{part ...
- shell脚本监控阿里云专线网络状态,若不通通过触发阿里云的进程监控报警
#!/bin/bash while [ 1 ] do rtt=`ping -c 3 15.0.160.18 |grep rtt |awk '{print $4}' |awk -F'/' '{print ...
- 【IntelliJ IDEA学习之六】IntelliJ IDEA 调试
版本:IntelliJIDEA2018.1.4 一.设置热部署1.自动编译 2.配置hotswap 3.开启compiler.automake.allow.when.app.running CTRL ...
- 面试题(Python)
面试题 字符串反向输出 s = "给阿姨倒杯卡布奇诺"反向输出S:print(s[::-1]) 面试必问:赋值,浅拷贝,深拷贝 赋值:多个变量指到相同内存浅拷贝中所有的元素,不管第 ...
- 基于网络拓扑图通过RCMS对网络进行配置
目录 基于网络拓扑图通过RCMS对网络进行配置 一些基本命令 对网络拓扑图1的简单配置 二层交换机S3 三层交换机 S2 实验结果 对网络拓扑图2的简单配置 NAT.ACL配置公网IP 基于网络拓扑图 ...