I find that the private field metricsService at Line 36 in the file 'ninja/ninja-metrics/src/main/java/ninja/metrics/InstrumentedCache.java' on the develop branch is only assigned and used in the method InstrumentedCache. Therefore, this field can be removed from the class, and become a local variable in the method InstrumentedCache. Besides, for method init, the field metricsService can be converted to an input parameter.This transformation will normally reduce memory usage and improve readability of your code.I will be happy if this transformation is helpful.
private MetricsService metricsService; // line 36 this field can be replaced by local variable
InstrumentedCache(Cache cache, MetricsService metricsService) {
this.underlyingCache = cache;
// MetricsService metricsService = metricsService;
this.metricsService = metricsService;
// init(metricsService);
init();
}
// private void init(MetricsService metricsService)
private void init() {
MetricRegistry registry = metricsService.getMetricRegistry();
hitCounter = registry.counter("ninja.cache.hits");
missCounter = registry.counter("ninja.cache.miss");
}
Hi,
I find that the private field metricsService at Line 36 in the file 'ninja/ninja-metrics/src/main/java/ninja/metrics/InstrumentedCache.java' on the develop branch is only assigned and used in the method InstrumentedCache. Therefore, this field can be removed from the class, and become a local variable in the method InstrumentedCache. Besides, for method init, the field metricsService can be converted to an input parameter.This transformation will normally reduce memory usage and improve readability of your code.I will be happy if this transformation is helpful.