2024-05-06 12:56:56 +08:00
|
|
|
package hae.cache;
|
2023-10-12 21:38:27 +08:00
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
import com.github.benmanes.caffeine.cache.Cache;
|
|
|
|
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
|
|
|
|
2024-05-12 19:02:38 +08:00
|
|
|
import java.util.Map;
|
2024-05-23 12:00:13 +08:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2023-10-12 21:38:27 +08:00
|
|
|
|
2024-05-06 12:56:56 +08:00
|
|
|
public class CachePool {
|
2024-05-23 12:00:13 +08:00
|
|
|
private static final int MAX_SIZE = 100000;
|
|
|
|
|
private static final int EXPIRE_DURATION = 5;
|
|
|
|
|
|
|
|
|
|
private static final Cache<String, Map<String, Map<String, Object>>> cache =
|
|
|
|
|
Caffeine.newBuilder()
|
|
|
|
|
.maximumSize(MAX_SIZE)
|
|
|
|
|
.expireAfterWrite(EXPIRE_DURATION, TimeUnit.HOURS)
|
|
|
|
|
.build();
|
2023-10-12 21:38:27 +08:00
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
public static void put(String key, Map<String, Map<String, Object>> value) {
|
2023-10-12 21:38:27 +08:00
|
|
|
cache.put(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
public static Map<String, Map<String, Object>> get(String key) {
|
|
|
|
|
return cache.getIfPresent(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void remove(String key) {
|
|
|
|
|
cache.invalidate(key);
|
2023-10-12 21:38:27 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
public static void clear() {
|
|
|
|
|
cache.invalidateAll();
|
2023-10-12 21:38:27 +08:00
|
|
|
}
|
|
|
|
|
}
|