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);
    }
相关推荐
知我Deja_Vu5 天前
redisCommonHelper.generateCode(“GROUP“),Redis 生成码方法
数据库·redis·缓存
莫寒清5 天前
Mybatis的插件原理
面试·mybatis
奇点爆破XC5 天前
Redis迁移
数据库·redis·bootstrap
没有bug.的程序员5 天前
电商秒杀系统深度进阶:高并发流量建模、库存零超卖内核与 Redis+MQ 闭环
数据库·redis·缓存·高并发·电商秒杀·流量建模·库存零超卖
troublea5 天前
ThinkPHP3.x高效学习指南
mysql·nginx·缓存
troublea5 天前
ThinkPHP6快速入门指南
数据库·mysql·缓存
莫寒清5 天前
MyBatis 中动态 SQL 的作用
面试·mybatis
Emotional。5 天前
AI Agent 性能优化和成本控制
人工智能·深度学习·机器学习·缓存·性能优化
吹晚风吧5 天前
实现一个mybatis插件,方便在开发中清楚的看出sql的执行及执行耗时
java·sql·mybatis
码云数智-大飞5 天前
像写 SQL 一样搜索:dbVisitor 如何用 MyBatis 范式颠覆 ElasticSearch 开发
sql·elasticsearch·mybatis