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
This commit is contained in:
parent
d6bc3f0bc6
commit
830c4c996f
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue