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();
|
}
|
}
|