Compare commits
1 Commits
fix#cache
...
feature#sn
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17838a74d2 |
@@ -103,6 +103,12 @@
|
|||||||
<artifactId>sshd-core</artifactId>
|
<artifactId>sshd-core</artifactId>
|
||||||
<version>2.8.0</version>
|
<version>2.8.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- snmp mib -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.snmp4j</groupId>
|
||||||
|
<artifactId>snmp4j</artifactId>
|
||||||
|
<version>2.8.9</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -2,7 +2,6 @@ package com.usthe.collector.collect.common.cache;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存key唯一标识符
|
* 缓存key唯一标识符
|
||||||
@@ -11,7 +10,6 @@ import lombok.ToString;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@ToString
|
|
||||||
public class CacheIdentifier {
|
public class CacheIdentifier {
|
||||||
|
|
||||||
private String ip;
|
private String ip;
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class CommonCache {
|
public class CommonCache {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认缓存时间 800s
|
* 默认缓存时间 10minute
|
||||||
*/
|
*/
|
||||||
private static final long DEFAULT_CACHE_TIMEOUT = 800 * 1000L;
|
private static final long DEFAULT_CACHE_TIMEOUT = 10 * 60 * 1000L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认最大缓存数量
|
* 默认最大缓存数量
|
||||||
@@ -173,11 +173,9 @@ public class CommonCache {
|
|||||||
public Optional<Object> getCache(Object key, boolean refreshCache) {
|
public Optional<Object> getCache(Object key, boolean refreshCache) {
|
||||||
Long[] cacheTime = timeoutMap.get(key);
|
Long[] cacheTime = timeoutMap.get(key);
|
||||||
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
|
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
|
||||||
log.warn("[cache] not hit the cache, key {}.", key);
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
|
if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
|
||||||
log.warn("[cache] is timeout, key {}.", key);
|
|
||||||
timeoutMap.remove(key);
|
timeoutMap.remove(key);
|
||||||
cacheMap.remove(key);
|
cacheMap.remove(key);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
|||||||
// 设置查询最大行数1000行
|
// 设置查询最大行数1000行
|
||||||
statement.setMaxRows(1000);
|
statement.setMaxRows(1000);
|
||||||
JdbcConnect jdbcConnect = new JdbcConnect(connection);
|
JdbcConnect jdbcConnect = new JdbcConnect(connection);
|
||||||
CommonCache.getInstance().addCache(identifier, jdbcConnect);
|
CommonCache.getInstance().addCache(identifier, jdbcConnect, 10000L);
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user