|
|
|
@ -27,7 +27,9 @@ import org.springframework.boot.actuate.cache.CacheStatisticsProvider;
|
|
|
|
|
import org.springframework.boot.actuate.metrics.Metric;
|
|
|
|
|
import org.springframework.cache.Cache;
|
|
|
|
|
import org.springframework.cache.CacheManager;
|
|
|
|
|
import org.springframework.cache.transaction.TransactionAwareCacheDecorator;
|
|
|
|
|
import org.springframework.core.ResolvableType;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
|
|
|
@ -87,7 +89,7 @@ public class CachePublicMetrics implements PublicMetrics {
|
|
|
|
|
List<CacheManagerBean> cacheManagerBeans) {
|
|
|
|
|
for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
|
|
|
|
|
CacheManager cacheManager = cacheManagerBean.getCacheManager();
|
|
|
|
|
Cache cache = cacheManager.getCache(cacheName);
|
|
|
|
|
Cache cache = unwrapIfNecessary(cacheManager.getCache(cacheName));
|
|
|
|
|
CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
|
|
|
|
|
if (statistics != null) {
|
|
|
|
|
String prefix = cacheName;
|
|
|
|
@ -100,6 +102,14 @@ public class CachePublicMetrics implements PublicMetrics {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Cache unwrapIfNecessary(Cache cache) {
|
|
|
|
|
if (ClassUtils.isPresent("org.springframework.cache.transaction.TransactionAwareCacheDecorator",
|
|
|
|
|
getClass().getClassLoader())) {
|
|
|
|
|
return TransactionAwareCacheDecoratorHandler.unwrapIfNecessary(cache);
|
|
|
|
|
}
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
|
private CacheStatistics getCacheStatistics(Cache cache, CacheManager cacheManager) {
|
|
|
|
|
if (this.statisticsProviders != null) {
|
|
|
|
@ -140,4 +150,19 @@ public class CachePublicMetrics implements PublicMetrics {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class TransactionAwareCacheDecoratorHandler {
|
|
|
|
|
|
|
|
|
|
private static Cache unwrapIfNecessary(Cache cache) {
|
|
|
|
|
try {
|
|
|
|
|
if (cache instanceof TransactionAwareCacheDecorator) {
|
|
|
|
|
return ((TransactionAwareCacheDecorator) cache).getTargetCache();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (NoClassDefFoundError ex) {
|
|
|
|
|
// Ignore
|
|
|
|
|
}
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|