From 43e00202aff53b131c04f165433d8440fa7b1fc1 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Tue, 27 Feb 2024 15:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E7=BC=93=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E9=97=B4=2030min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mocking/core/sip/service/VideoCacheManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/service/VideoCacheManager.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/service/VideoCacheManager.java index 0ecbc04..70d4a4b 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/service/VideoCacheManager.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/service/VideoCacheManager.java @@ -1,5 +1,7 @@ package cn.skcks.docking.gb28181.mocking.core.sip.service; +import cn.hutool.cache.CacheUtil; +import cn.hutool.cache.impl.TimedCache; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.IoUtil; @@ -36,7 +38,8 @@ public class VideoCacheManager { @Qualifier(MockingExecutor.EXECUTOR_BEAN_NAME) private final Executor executor; - private final ConcurrentMap>> tasks = new ConcurrentHashMap<>(); + private final TimedCache>> tasks = + CacheUtil.newTimedCache(TimeUnit.MINUTES.toMillis(30)); private final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); @@ -60,7 +63,7 @@ public class VideoCacheManager { public void addTask(String deviceCode, Date startTime, Date endTime){ String name = fileName(deviceCode, startTime, endTime); - if(tasks.get(name) != null){ + if(tasks.get(name, false) != null){ return; } @@ -69,7 +72,7 @@ public class VideoCacheManager { public CompletableFuture> get(String deviceCode, Date startTime, Date endTime){ String name = fileName(deviceCode, startTime, endTime); - CompletableFuture> future = tasks.get(name); + CompletableFuture> future = tasks.get(name, false); if(future == null){ File realFile = Paths.get(deviceProxyConfig.getPreDownloadForRecordInfo().getCachePath(),fileName(deviceCode, startTime, endTime) + ".mp4").toFile(); if(realFile.exists()){