I'm using Guava Cache lib ,and i wanna check the statistics of the cache here is my code :
refreshCache = CacheBuilder.newBuilder()
.refreshAfterWrite(1, TimeUnit.MINUTES)
.maximumSize(5)
.recordStats()
.build(
new CacheLoader<String, Map<String,Object>>() {
public Map<String,Object> load(String key) throws Exception {
loader();
}
});
stats = refreshCache.stats();
delta = refreshCache.stats()
.minus(stats);
}
logger.info("Stats:{}",stats);
logger.info("delta:{}",delta);
i've called recordeStats()
to active the Stats , but when i print the stats , it's all 0 .
You forgot to activate the cache recording by adding recordStats()
to CacheBuilder.newBuilder()
.
You can not instantiate stats(). It is a factory which copies over the cache values to a final statistic. So please use logger.info(refreshCache.stats()) during runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With