1 回答
TA贡献1798条经验 获得超7个赞
map.set
使附近的缓存无效,不要将新值放在那里Near Cache 仅用于基于键的访问,您的循环根本不会命中 Near Cache。您需要像这样更改循环中的第二行:
String value = nearCacheMap.get(entrySet.getKey());
或将循环更改为 keySet
for (Double key : nearCacheMap.keySet()) { String value = entrySet.getValue(key); }
即使更改后,您仍然会看到 0,因为您只进行了 1 次获取操作,这是缓存未命中。如果您多次重复循环和统计打印,您将看到:
---------------------------Before Sort----------------------------------
------------------------------------------------Read Both---------------------------------------------------
Near Cache hit/miss ratio = 0 / 100000
Near cache implemented or not 10
EndTime timeDifference : 1548313357643 1548313362527 4884
------------------------------------------------Read Both---------------------------------------------------
Near Cache hit/miss ratio = 10 / 199990
Near cache implemented or not 10
EndTime timeDifference : 1548313357643 1548313367155 9512
------------------------------------------------Read Both---------------------------------------------------
Near Cache hit/miss ratio = 20 / 299980
Near cache implemented or not 10
EndTime timeDifference : 1548313357643 1548313371688 14045
添加回答
举报