SpringBootCache缓存——j2cache

文章目录

缓存供应商变更:j2cache


java 复制代码
<!-- https://mvnrepository.com/artifact/net.oschina.j2cache/j2cache-core -->
        <dependency>
            <groupId>net.oschina.j2cache</groupId>
            <artifactId>j2cache-core</artifactId>
            <version>2.8.4-release</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.oschina.j2cache/j2cache-spring-boot2-starter -->
        <dependency>
            <groupId>net.oschina.j2cache</groupId>
            <artifactId>j2cache-spring-boot2-starter</artifactId>
            <version>2.8.0-release</version>
        </dependency>

        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
        </dependency>
java 复制代码
j2cache:
  config-location: j2cache.properties
java 复制代码
# 一级缓存的配置
j2cache.L1.provider_class  = ehcache
ehcache.configXml = ehcache.xml

# 设置是否启用二级缓存
j2cache.l2-cache-open = false

# 二级缓存的配置
j2cache.L2.provider_class=net.oschina.j2cache.cache.support.redis.SpringRedisProvider
j2cache.L2.config_section = redis
redis.hosts = localhost:6379
redis.password = 123456

# 一级缓存的数据如何到达二级缓存
j2cache.broadcast = net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy


java 复制代码
    @Autowired
    private CacheChannel cacheChannel;

    @Override
    public String sendCodeToSMS(String tele) {
        String code = codeUtils.generator(tele);
        cacheChannel.set("sms",tele,code);
        return code;
    }

    @Override
    public Boolean checkCode(SMSCode smsCode) {
        String code = cacheChannel.get("sms", smsCode.getTele()).asString();
        return smsCode.getCode().equals(code);
    }
相关推荐
老毛肚3 小时前
MyBatis插件原理及Spring集成
java·spring·mybatis
ALex_zry6 小时前
Redis Cluster 分布式缓存架构设计与实践
redis·分布式·缓存
马尔代夫哈哈哈8 小时前
MyBatis 入门与实战:从配置到CRUD一站式指南
mybatis
Jul1en_9 小时前
【MyBatis/plus】核心配置、插件与 MyBatis-Plus 构造器 Wrapper
mybatis
shuair11 小时前
redis缓存预热、缓存击穿、缓存穿透、缓存雪崩
redis·spring·缓存
LiZhen79811 小时前
SpringBoot 实现动态切换数据源
java·spring boot·mybatis
珹洺11 小时前
Bootstrap-HTML(二)深入探索容器,网格系统和排版
前端·css·bootstrap·html·dubbo
上架ipa12 小时前
redis图形化客户端功能对比
redis·缓存
我是Superman丶12 小时前
在 PostgreSQL 中使用 JSONB 类型并结合 MyBatis-Plus 实现自动注入,主要有以下几种方案
数据库·postgresql·mybatis
Pluto_CSND13 小时前
基于mybatis-generator插件生成指定数据表的实体类、xml文件和dao层接口
mybatis