mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Update] CacheStore-local 适配更改;
[Update] LocalCacheStoreFactory 适配 CacheStore-api 对 CacheStoreFactory 的更改;
This commit is contained in:
parent
4f877a03c2
commit
10c92d8812
@ -26,6 +26,7 @@ import net.lamgc.cgj.bot.cache.convert.StringConverter;
|
|||||||
* 最简单的缓存实现, 无持久化功能.
|
* 最简单的缓存实现, 无持久化功能.
|
||||||
* @author LamGC
|
* @author LamGC
|
||||||
*/
|
*/
|
||||||
|
@Factory(name = "Local", priority = FactoryPriority.PRIORITY_LOWEST)
|
||||||
public class LocalCacheStoreFactory implements CacheStoreFactory {
|
public class LocalCacheStoreFactory implements CacheStoreFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -48,4 +49,15 @@ public class LocalCacheStoreFactory implements CacheStoreFactory {
|
|||||||
return new HashMapCacheStore<>();
|
return new HashMapCacheStore<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内存使用阀值.
|
||||||
|
* <p>当内存使用到了指定百分比时, 将禁止创建 CacheStore.
|
||||||
|
*/
|
||||||
|
private final static double MEMORY_USAGE_THRESHOLD = 85;
|
||||||
|
@Override
|
||||||
|
public boolean canGetCacheStore() {
|
||||||
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
double memoryUsedPercentage = (double) runtime.totalMemory() / runtime.maxMemory();
|
||||||
|
return memoryUsedPercentage < MEMORY_USAGE_THRESHOLD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user