package com.yx.face.boot.component.cache;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @description: GuavaCache <br>
 * @date: 2021/4/21 16:07 <br>
 * @author: PWB <br>
 */

@Component
public class GuavaCacheService {


    private Cache<String, String> cache;


    public GuavaCacheService() {
        this.cache = CacheBuilder.newBuilder()
                .maximumSize(1000)
                .expireAfterWrite(1, TimeUnit.DAYS)
                .build();
    }

    public void setValue(String key, String value) {
        cache.put(key, value);
    }

    public String getValue(String key) {
        return cache.getIfPresent(key);
    }

    public void remove(String key) {
        cache.invalidate(key);
    }

}
