Ehcache 2.10.6 命中统计未增加

Ehcache 2.10.6 hit statistic not being incremented

我在我的一个项目中设置了一个缓存,以及如下自定义健康指标:

@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 Expired Count":0}}

我在其他项目中访问缓存的代码是:

Cacheable cachedResult = CacheManager.getInstance().getCache(request);
if (cachedResult != null)
{
    CustomResponse response = (CustomResponse) cachedResult.getObject();
    return response;
}

我可以确认这个块已经进入,并且缓存中确实有数据。

我不知道为什么点击统计没有更新。如有任何帮助,我们将不胜感激!

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