【发布时间】:2019-10-11 14:17:52
【问题描述】:
我在我的一个项目中设置了一个缓存,以及如下的自定义健康指标:
@Component
public class CustomHealthIndicator extends AbstractHealthIndicator
{
@Override
protected void doHealthCheck(Health.Builder builder)
{
CacheManager cacheManagerInstance = CacheManager.getInstance();
Ehcache cache = cacheManagerInstance.getCache("myCache");
builder.up()
.withDetail("Cache Size", cache.getSize())
.withDetail("Cache Hit Count", cache.getStatistics().cacheHitCount())
.withDetail("Cache Miss Count", cache.getStatistics().cacheMissCount())
.withDetail("Cache Put Count", cache.getStatistics().cachePutCount())
.withDetail("Cache Remove Count", cache.getStatistics().cacheRemoveCount())
.withDetail("Cache Expired Count", cache.getStatistics().cacheExpiredCount());
}
当我在本地运行它并转到 localhost:8080/actuator/health 时,所有其他统计信息都会更新,但点击量没有。
{"status":"UP","details":{"Cache Size":9,"Cache Hit Count":0,"Cache Miss Count":9,"Cache Put Count":9,"Cache Remove Count":0,"Cache 过期计数":0}}
我在另一个项目中访问缓存的代码是:
Cacheable cachedResult = CacheManager.getInstance().getCache(request);
if (cachedResult != null)
{
CustomResponse response = (CustomResponse) cachedResult.getObject();
return response;
}
我可以确认进入了这个块并且缓存中确实有数据。
我不知道为什么没有更新点击统计信息。任何帮助将不胜感激!
【问题讨论】:
标签: java spring spring-boot ehcache spring-boot-actuator