[Update] CacheStore-local 适配更改;

[Update] LocalCacheStoreFactory 适配 CacheStore-api 对 CacheStoreFactory 的更改;
This commit is contained in:
LamGC 2020-09-12 02:59:40 +08:00
parent 4f877a03c2
commit 10c92d8812
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -26,6 +26,7 @@ import net.lamgc.cgj.bot.cache.convert.StringConverter;
* 最简单的缓存实现, 无持久化功能.
* @author LamGC
*/
@Factory(name = "Local", priority = FactoryPriority.PRIORITY_LOWEST)
public class LocalCacheStoreFactory implements CacheStoreFactory {
@Override
@ -48,4 +49,15 @@ public class LocalCacheStoreFactory implements CacheStoreFactory {
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;
}
}