package com.ruoyi.cache;

import com.alibaba.fastjson2.JSON;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.ruoyi.database.domain.vo.SmsVO;
import org.springframework.stereotype.Component;

/**
 * 验证码缓存
 */
@Component
public class SmsCache {

    /**
     * key: phone
     */
    private static final Cache<String, String> cache = Caffeine.newBuilder().build();

    public static void put(SmsVO bean) {
        cache.put(bean.getPhone(), JSON.toJSONString(bean));
    }

    public static String get(String key) {
        return cache.get(key, s -> {
            try {
                return "";
            } catch (Exception e) {
                return "";
            }
        });
    }

}
