燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2024-03-21 c2caa2b7bbdfb9ddc4a652ade9ae96e96ea92929
src/main/java/com/yssh/utils/CacheUtils.java
对比新文件
@@ -0,0 +1,35 @@
package com.yssh.utils;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.concurrent.TimeUnit;
public class CacheUtils {
    private static @NonNull Cache<String, Object> cache;
    public static void init() {
        cache = Caffeine.newBuilder()
                .initialCapacity(2)
                .maximumSize(1024)
                .expireAfterWrite(24, TimeUnit.HOURS)
                .build();
    }
    public static Object get(String key) {
        return cache.getIfPresent(key);
    }
    public static void put(String key, Object obj) {
        cache.put(key, obj);
    }
    public static void remove(String key) {
        cache.invalidate(key);
    }
    public static void clear() {
        cache.invalidateAll();
    }
}