燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-07-14 db44f336e46825afc855466512065cc08e5790bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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();
    }
}