【问题标题】:Ehcache 2.10.6 hit statistic not being incrementedEhcache 2.10.6 命中统计未增加
【发布时间】: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


    【解决方案1】:

    原来我的对象没有被正确序列化,所以当它在缓存中搜索它们时没有找到它们。

    【讨论】:

      猜你喜欢
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 1970-01-01
      • 2011-01-01
      • 2011-02-24
      • 2018-06-26
      • 1970-01-01
      相关资源
      最近更新 更多