Showing
1 changed file
with
17 additions
and
2 deletions
1 | 1 | package org.thingsboard.server.common.data.yunteng.utils.tools; |
2 | - | |
3 | 2 | import java.time.LocalDateTime; |
4 | 3 | import java.util.HashMap; |
4 | +import java.util.Iterator; | |
5 | 5 | import java.util.Map; |
6 | 6 | |
7 | 7 | public class VideoUrlUtils { |
8 | 8 | |
9 | - private static Map<String, Map<String,Object>> videoUrlData = new HashMap<>(); | |
9 | + private static final Map<String, Map<String,Object>> videoUrlData = new HashMap<>(); | |
10 | 10 | |
11 | 11 | |
12 | 12 | public static void putVideoUrl(String key, String url, LocalDateTime expireTime) { |
13 | + //检查哪些过期了,过期了的就移除 | |
14 | + checkVideoUrlData(); | |
13 | 15 | Map<String,Object> videoUrlInfo = new HashMap<>(); |
14 | 16 | videoUrlInfo.put("url",url); |
15 | 17 | videoUrlInfo.put("expireTime",expireTime); |
... | ... | @@ -26,4 +28,17 @@ public class VideoUrlUtils { |
26 | 28 | //如果过期了返回null |
27 | 29 | return nowTime.isAfter(expireTime) ? null : videoUrlInfo.get("url").toString(); |
28 | 30 | } |
31 | + private static void checkVideoUrlData(){ | |
32 | + if(!videoUrlData.isEmpty()){ | |
33 | + Iterator<Map.Entry<String, Map<String, Object>>> iterator = videoUrlData.entrySet().iterator(); | |
34 | + while (iterator.hasNext()){ | |
35 | + Map.Entry<String, Map<String, Object>> entry = iterator.next(); | |
36 | + LocalDateTime expireTime = (LocalDateTime) entry.getValue().get("expireTime"); | |
37 | + LocalDateTime nowTime = LocalDateTime.now(); | |
38 | + if(nowTime.isAfter(expireTime)){ | |
39 | + iterator.remove(); | |
40 | + } | |
41 | + } | |
42 | + } | |
43 | + } | |
29 | 44 | } | ... | ... |