gpt4 book ai didi

Java 缓存系统 - 查找 map 大小

转载 作者:行者123 更新时间:2023-12-01 11:06:55 26 4
gpt4 key购买 nike

我正在使用 Java 缓存系统 (JCS - https://commons.apache.org/proper/commons-jcs/ ),我需要查找缓存的大小(来自 org.apache.commons.jcs.access.CacheAccess 类)

通过 CacheAccess.getStats(),我可以获得一个字符串,该字符串提供缓存的统计信息

例如

String stats = ((ICacheAccess<String, Book>) cache).getStats();

并且会给我很多信息

Region Name = bookCache
HitCountRam = 0
HitCountAux = 0
---------------------------Memory Cache
List Size = 5015
Map Size = 5015
Put Count = 5015
Hit Count = 0
Miss Count = 0
---------------------------Indexed Disk Cache
Is Alive = true
Key Map Size = 0
Data File Length = 0
Hit Count = 0
Bytes Free = 0
Optimize Operation Count = 0
Times Optimized = 0
Recycle Count = 0
Recycle Bin Size = 0
Startup Size = 0
Purgatory Hits = 0
Purgatory Size = 0
Working = true
Alive = false
Empty = true
Size = 0

但我需要的只是 map 或列表大小。

任何想法 - 除了正则表达式:-)

最佳答案

你可以试试

List<IStatElement> stats = ((ICacheAccess<String, Book>) cache).getStatistics().getStatsElements();
// using CollectionsUtil from commons-collection
CollectionsUtil.select(stats, new Predicate<IStatElement>() {
public boolean evaluate(IStatElement elem) {
String name = elem.getName();
return "List Size".equals(name) || "Map Size".equals(name);
}
});

关于Java 缓存系统 - 查找 map 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32855582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com