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);
    }
相关推荐
starzy19903 小时前
Flink 优化之网络缓存优化及参数详解:从数据传输机制到反压原理的生产调优指南
网络·缓存·flink
ShineWinsu4 小时前
对于Redis:string类型的解析
java·c++·redis·分布式·缓存·面试·string
CoLiuRs6 小时前
电商价格是怎样算出来的
数据库·redis·缓存
蜗牛互联网11 小时前
HSTU在Dynamo-Triton中的AOTI与KV缓存验收方法
java·人工智能·后端·缓存
hweiyu0021 小时前
Redis命令:HMGET
redis·缓存
CarIise1 天前
MyBatis动态SQL:从条件拼接到底层原理实战
mybatis
陕西企来客1 天前
豆包检索层 9 月迭代后信源陈旧的核心 —— 缓存策略的可用性优先转向
缓存
CarIise1 天前
Spring Boot图片展示与统一返回格式:从资源映射到泛型封装实战
mybatis
三掌柜6661 天前
ArkWeb 手记 07|缓存和离线页怎么做
缓存·harmonyos
钝挫力PROGRAMER2 天前
开发踩坑记:MyBatis selectKey、空 SQL
数据库·sql·mybatis