package com.muyu.carData.util;


import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.stereotype.Component;

/** 缓存工具类
 * @Author：张腾
 * @Package：com.muyu.carData.util
 * @Project：cloud-server-8
 * @name：CacheUtil
 * @Date：2024/10/4 10:42
 */
@Component
public class CacheUtil<T> {

    private final Cache<String,T> cache;

    public CacheUtil() {
        this.cache = Caffeine.newBuilder()
                .maximumSize(500L)
                .build();
    }

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

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

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