j2cache缓存整合框架学习

j2cache缓存框架:可整合整合其他缓存,实现多级缓存。
基于:ehcache + redis

  1. 依赖
    依赖:lombok
    所需依赖:j2cache-core、j2cache-spring-boot2-starter(含有spring整合redis依赖,日志为logback(spring默认slf4j,可排除依赖))、ehcache

  2. springboot配置文件application.yml:

server:
  port: 80

j2cache:
  config-location: j2cache的配置文件名.properties
  1. 将cache配置文件j2cache.properties
    可从外部库External libraries,导入的依赖的jar Maven:net.oschina.j2cache-core-2.8.4-release中复制
    自定义j2cache.properties:

#一级缓存:    将ehcache作为一级缓存
j2cache.L1.provider_class = ehcache
ehcache.configXml = ehcache.xml   #ehcache配置地址

#设置是否启用二级缓存
c2cache.l2-cche-open = true

#二级缓存:   starter依赖中类全限定类名

j2cache.L2.provider_class =net.oschina.j2cache.cache.support.redis.SpringRedisProvider
j2cache.L2.config_section = redis //将以下带有redis的作为上类的配置
redis.hosts = localhost:6379


#一级缓存如何到达二级:使用redis的发布与订阅功能,接收一级缓存的信息
j2cache.broadcast = net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy

redis.mode = single

注:以上类的全限定类或配置文件都可以到IDEA的扩展库中复制或查询

  1. 操作缓存
    缓存对象:
    @Autowired
    private CacheChannel cacheChannel;
    放入数据:cacheChannel.set(String region, String key, Object value)
    取出:cacheChannel.get(“sms”,smsCode.getTele()).asString();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值