mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Fix] AutoCleanTimer 修复自动清除定时器没有重复工作;
[Fix] LocalHashCacheStore 修复clean方法抛出'ConcurrentModificationException'异常的问题; [Change] CacheStoreCentral 调整PreLoadData的热点缓存时间; [Change] HotDataCacheStore 将最近获取的Key重置其过期时间, 调整clean过程;
This commit is contained in:
parent
cbe0a38f59
commit
6443ba68ab
@ -18,7 +18,7 @@ public class AutoCleanTimer extends TimerTask {
|
||||
private final static Logger log = LoggerFactory.getLogger(AutoCleanTimer.class);
|
||||
|
||||
static {
|
||||
cleanTimer.schedule(new AutoCleanTimer(), 100L);
|
||||
cleanTimer.schedule(new AutoCleanTimer(), 100L, 100L);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +84,8 @@ public final class CacheStoreCentral {
|
||||
CacheStoreUtils.hashLocalHotDataStore(
|
||||
new JsonRedisCacheStore(BotGlobal.getGlobal().getRedisServer(),
|
||||
"illustPreLoadData", BotGlobal.getGlobal().getGson()),
|
||||
1800000, 900000);
|
||||
// 600000, 120000);
|
||||
60000, 1);
|
||||
/**
|
||||
* 搜索内容缓存, 有效期 2 小时
|
||||
*/
|
||||
|
@ -75,6 +75,9 @@ public class HotDataCacheStore<T> implements CacheStore<T>, Cleanable {
|
||||
log.trace("Current缓存库更新完成.");
|
||||
result = parentResult;
|
||||
} else {
|
||||
// 更新该Key的过期时间
|
||||
current.update(key, result,
|
||||
expireTime + (expireFloatRange <= 0 ? 0 : random.nextInt(expireFloatRange)));
|
||||
log.trace("Current缓存库缓存命中.");
|
||||
}
|
||||
return result;
|
||||
@ -138,10 +141,14 @@ public class HotDataCacheStore<T> implements CacheStore<T>, Cleanable {
|
||||
* <p>该方法仅清理Current缓存库, 不会对上游缓存库造成影响.</p>
|
||||
*/
|
||||
@Override
|
||||
public void clean() {
|
||||
for(String key : this.current.keys()) {
|
||||
if(current.exists(key)) {
|
||||
current.remove(key);
|
||||
public void clean() throws Exception {
|
||||
if(current instanceof Cleanable) {
|
||||
((Cleanable) current).clean();
|
||||
} else {
|
||||
for(String key : this.current.keys()) {
|
||||
if (!current.exists(key)) {
|
||||
current.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,7 @@ package net.lamgc.cgj.bot.cache;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
@ -151,11 +148,14 @@ public class LocalHashCacheStore<T> implements CacheStore<T>, Cleanable {
|
||||
@Override
|
||||
public void clean() {
|
||||
Date currentDate = new Date();
|
||||
Set<String> expireKeySet = new HashSet<>();
|
||||
cache.forEach((key, value) -> {
|
||||
if(value.isExpire(currentDate)) {
|
||||
cache.remove(key);
|
||||
expireKeySet.add(key);
|
||||
}
|
||||
});
|
||||
|
||||
expireKeySet.forEach(cache::remove);
|
||||
}
|
||||
|
||||
public static class CacheObject<T> implements Comparable<CacheObject<T>> {
|
||||
|
Loading…
Reference in New Issue
Block a user