peng
2026-03-18 e59a0201057ba67cad425fed804c82ff4ba0c6f1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.tievd.jyz.cache;
 
import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.collection.ListUtil;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
 
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
 
/**
 * 时间和加油记录表对应关系临时缓存
 * @author timi
 */
public class EventCodeRelOilCache {
 
    /** 事件临时缓存,用于图片和视频和源事件的对应
     * eventCode:oilRecordId */
    private final static Cache<String, Set<Long>> EVENT_CODE_REL_OIL_RECORD_CACHE_MAP = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build();
 
    /**
     * 压入
     * @param eventCode
     * @param oilRecordId
     */
    public static void put(String eventCode,Long oilRecordId){
        Set<Long> oilRecordIdSet = EVENT_CODE_REL_OIL_RECORD_CACHE_MAP.getIfPresent(eventCode);
        if(oilRecordIdSet == null){
            oilRecordIdSet = new ConcurrentHashSet<>();
            EVENT_CODE_REL_OIL_RECORD_CACHE_MAP.put(eventCode,oilRecordIdSet);
        }
        oilRecordIdSet.add(oilRecordId);
    }
 
    /**
     * 获取
     * @param eventCode
     * @return
     */
    public static List<Long> get(String eventCode){
        return ListUtil.toList(EVENT_CODE_REL_OIL_RECORD_CACHE_MAP.getIfPresent(eventCode));
    }
 
    /**
     * 数量
     * @param eventCode
     * @return
     */
    public static int count(String eventCode){
        Set<Long> set = EVENT_CODE_REL_OIL_RECORD_CACHE_MAP.getIfPresent(eventCode);
        if(set != null){
            return set.size();
        }
        return 0;
    }
 
    /**
     * 移除
     * @param eventCode
     * @return
     */
    public static List<Long> remove(String eventCode){
        List<Long> oilRecordIdList = ListUtil.toList(EVENT_CODE_REL_OIL_RECORD_CACHE_MAP.getIfPresent(eventCode));
        EVENT_CODE_REL_OIL_RECORD_CACHE_MAP.invalidate(eventCode);
        return oilRecordIdList;
    }
 
}