简介
J2Cache 是 OSChina 目前正在使用的两级缓存框架(要求至少 Java 8)。第一级缓存使用内存(同时支持 Ehcache 2.x、Ehcache 3.x 和 Caffeine),第二级缓存使用 Redis(推荐)/Memcached 。 由于大量的缓存读取会导致 L2 的网络成为整个系统的瓶颈,因此 L1 的目标是降低对 L2 的读取次数。 该缓存框架主要用于集群环境中。单机也可使用,用于避免应用重启导致的缓存冷启动后对后端业务的冲击。
导入jar包
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId>
<version>2.7.8-release</version>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</dependency>
引入配置文件j2cache.properties
#J2Cache configuration
#########################################
#Cache Broadcast Method
#values:
#jgroups -> use jgroups's multicast
#redis -> use redis publish/subscribe mechanism (using jedis)
#lettuce -> use redis publish/subscribe mechanism (using lettuce, Recommend)
#rabbitmq -> use RabbitMQ publisher/consumer mechanism
#rocketmq -> use RocketMQ publisher/consumer mechanism
#none -> don't notify the other nodes in cluster
#xx.xxxx.xxxx.Xxxxx your own cache broadcast policy classname that implement net.oschina.j2cache.cluster.ClusterPolicy
#########################################
j2cache.broadcast = lettuce
#jgroups properties
#jgroups.channel.name = j2cache
#jgroups.configXml = /network.xml
#RabbitMQ properties
#rabbitmq.exchange = j2cache
#rabbitmq.host = 7.11.16