mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Change] LocalHashCacheStore 实现'Cleanable'接口, 增加'<init>(int, int, boolean)'构造函数以允许自动清理
[Update] LocalHashCacheStore 补充Javadoc内容; [Update] .gitignore 补充并整理忽略项;
This commit is contained in:
parent
f7f3c3beaf
commit
1f402fbbac
13
.gitignore
vendored
13
.gitignore
vendored
@ -1,6 +1,15 @@
|
|||||||
|
# Ignore test date folder
|
||||||
/pluginData/
|
/pluginData/
|
||||||
/logs/
|
/logs/
|
||||||
/.idea/
|
|
||||||
/CGJ_2.iml
|
|
||||||
/cookies.store
|
/cookies.store
|
||||||
/target/
|
/target/
|
||||||
|
|
||||||
|
# Ignore Idea files
|
||||||
|
/.idea/
|
||||||
|
/CGJ_2.iml
|
||||||
|
|
||||||
|
# Ignore Visual Studio Code files
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
/.settings/
|
||||||
|
@ -12,19 +12,45 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
* 基于Hashtable的本地缓存库
|
* 基于Hashtable的本地缓存库
|
||||||
* @param <T> 缓存类型
|
* @param <T> 缓存类型
|
||||||
*/
|
*/
|
||||||
public class LocalHashCacheStore<T> implements CacheStore<T> {
|
public class LocalHashCacheStore<T> implements CacheStore<T>, Cleanable {
|
||||||
|
|
||||||
private final Hashtable<String, CacheObject<T>> cache;
|
private final Hashtable<String, CacheObject<T>> cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一个基于Hashtable的本地缓存库
|
||||||
|
* @see Hashtable
|
||||||
|
*/
|
||||||
public LocalHashCacheStore() {
|
public LocalHashCacheStore() {
|
||||||
this(0);
|
this(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一个基于Hashtable的本地缓存库
|
||||||
|
* @param initialCapacity 初始容量
|
||||||
|
* @see Hashtable
|
||||||
|
*/
|
||||||
public LocalHashCacheStore(int initialCapacity) {
|
public LocalHashCacheStore(int initialCapacity) {
|
||||||
this(initialCapacity, 0F);
|
this(initialCapacity, 0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一个基于Hashtable的本地缓存库
|
||||||
|
* @param initialCapacity 初始容量
|
||||||
|
* @param loadFactor 重载因子
|
||||||
|
* @see Hashtable
|
||||||
|
*/
|
||||||
public LocalHashCacheStore(int initialCapacity, float loadFactor) {
|
public LocalHashCacheStore(int initialCapacity, float loadFactor) {
|
||||||
|
this(initialCapacity, loadFactor, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一个基于Hashtable的本地缓存库
|
||||||
|
* @param initialCapacity 初始容量
|
||||||
|
* @param loadFactor 重载因子
|
||||||
|
* @param autoClean 是否自动清理
|
||||||
|
* @see Hashtable
|
||||||
|
*/
|
||||||
|
public LocalHashCacheStore(int initialCapacity, float loadFactor, boolean autoClean) {
|
||||||
if(initialCapacity != 0) {
|
if(initialCapacity != 0) {
|
||||||
if(loadFactor <= 0F) {
|
if(loadFactor <= 0F) {
|
||||||
cache = new Hashtable<>(initialCapacity);
|
cache = new Hashtable<>(initialCapacity);
|
||||||
@ -34,6 +60,10 @@ public class LocalHashCacheStore<T> implements CacheStore<T> {
|
|||||||
} else {
|
} else {
|
||||||
cache = new Hashtable<>();
|
cache = new Hashtable<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(autoClean) {
|
||||||
|
AutoCleanTimer.add(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -118,6 +148,15 @@ public class LocalHashCacheStore<T> implements CacheStore<T> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clean() throws Exception {
|
||||||
|
Date currentDate = new Date();
|
||||||
|
cache.forEach((key, value) -> {
|
||||||
|
if(value.isExpire(currentDate)) {
|
||||||
|
cache.remove(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static class CacheObject<T> implements Comparable<CacheObject<T>> {
|
public static class CacheObject<T> implements Comparable<CacheObject<T>> {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user