From 2c4d3d80b078d7a1b55ba9faec7be2cbb628e115 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Mon, 14 Mar 2022 20:34:47 +0800 Subject: [PATCH] =?UTF-8?q?[collector]fix=20=E7=94=B1=E4=BA=8E=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=A4=8D=E7=94=A8=E4=B8=8D=E4=BD=B3=E9=80=A0=E6=88=90?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=BF=87=E5=A4=9A=E9=93=BE=E6=8E=A5=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collector/collect/common/cache/CacheIdentifier.java | 2 ++ .../usthe/collector/collect/common/cache/CommonCache.java | 6 ++++-- .../usthe/collector/collect/database/JdbcCommonCollect.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/collector/src/main/java/com/usthe/collector/collect/common/cache/CacheIdentifier.java b/collector/src/main/java/com/usthe/collector/collect/common/cache/CacheIdentifier.java index 75bc1e1..1edac6d 100644 --- a/collector/src/main/java/com/usthe/collector/collect/common/cache/CacheIdentifier.java +++ b/collector/src/main/java/com/usthe/collector/collect/common/cache/CacheIdentifier.java @@ -2,6 +2,7 @@ package com.usthe.collector.collect.common.cache; import lombok.Builder; import lombok.Data; +import lombok.ToString; /** * 缓存key唯一标识符 @@ -10,6 +11,7 @@ import lombok.Data; */ @Data @Builder +@ToString public class CacheIdentifier { private String ip; diff --git a/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java b/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java index 712c01a..819b9cb 100644 --- a/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java +++ b/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java @@ -21,9 +21,9 @@ import java.util.concurrent.TimeUnit; public class CommonCache { /** - * 默认缓存时间 10minute + * 默认缓存时间 800s */ - private static final long DEFAULT_CACHE_TIMEOUT = 10 * 60 * 1000L; + private static final long DEFAULT_CACHE_TIMEOUT = 800 * 1000L; /** * 默认最大缓存数量 @@ -173,9 +173,11 @@ public class CommonCache { public Optional getCache(Object key, boolean refreshCache) { Long[] cacheTime = timeoutMap.get(key); if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) { + log.warn("[cache] not hit the cache, key {}.", key); return Optional.empty(); } if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) { + log.warn("[cache] is timeout, key {}.", key); timeoutMap.remove(key); cacheMap.remove(key); return Optional.empty(); diff --git a/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java b/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java index 1331b26..300a838 100644 --- a/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java +++ b/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java @@ -134,7 +134,7 @@ public class JdbcCommonCollect extends AbstractCollect { // 设置查询最大行数1000行 statement.setMaxRows(1000); JdbcConnect jdbcConnect = new JdbcConnect(connection); - CommonCache.getInstance().addCache(identifier, jdbcConnect, 10000L); + CommonCache.getInstance().addCache(identifier, jdbcConnect); return statement; }