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);
    }
相关推荐
-Xie-10 小时前
Mysql杂志(十六)——缓存池
数据库·mysql·缓存
七夜zippoe10 小时前
缓存与数据库一致性实战手册:从故障修复到架构演进
数据库·缓存·架构
weixin_4569042710 小时前
跨域(CORS)和缓存中间件(Redis)深度解析
redis·缓存·中间件
MarkHard12320 小时前
如何利用redis使用一个滑动窗口限流
数据库·redis·缓存
island131421 小时前
【Redis#10】渐进式遍历 | 数据库管理 | redis_cli | RES
数据库·redis·bootstrap
心想事成的幸运大王21 小时前
Redis的过期策略
数据库·redis·缓存
wuyunhang1234561 天前
Redis---集群模式
数据库·redis·缓存
sensenlin911 天前
Mybatis中SQL全大写或全小写影响执行性能吗
数据库·sql·mybatis
BXCQ_xuan1 天前
软件工程实践四:MyBatis-Plus 教程(连接、分页、查询)
spring boot·mysql·json·mybatis
IAtlantiscsdn1 天前
Redis7底层数据结构解析
前端·数据结构·bootstrap