Commit 830c4c99 authored by Stephane Nicoll's avatar Stephane Nicoll

Update computation of ehcache statistics

Previously, the ehcache statistics were computed on the activity of the
last minute which gives a "live" overview. All others cache managers,
including JCache, provides a "cumulative" metrics (i.e. the hit/miss
ratio since the creation of the cache or the last time it got cleared).

Ths commit aligns the ehcache statistics to provide a similar semantics
as the other cache managers. The side effect is that the metrics are now
available, even if there is no cache activity at all at the moment.

Closes gh-4891
parent d6bc3f0b
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -35,7 +35,7 @@ public class EhCacheStatisticsProvider implements CacheStatisticsProvider<EhCach
DefaultCacheStatistics statistics = new DefaultCacheStatistics();
StatisticsGateway ehCacheStatistics = cache.getNativeCache().getStatistics();
statistics.setSize(ehCacheStatistics.getSize());
Double hitRatio = ehCacheStatistics.cacheHitRatio();
Double hitRatio = cacheHitRatio(ehCacheStatistics);
if (!hitRatio.isNaN()) {
// ratio is calculated 'racily' and can drift marginally above unity,
// so we cap it here
......@@ -46,4 +46,10 @@ public class EhCacheStatisticsProvider implements CacheStatisticsProvider<EhCach
return statistics;
}
private static Double cacheHitRatio(StatisticsGateway stats) {
long hitCount = stats.cacheHitCount();
long cacheMissCount = stats.cacheMissCount();
return ((double) hitCount) / (hitCount + cacheMissCount);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment