有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Ehcache 2.10.6命中统计数据未增加

我已经在我的一个项目中设置了缓存,以及自定义运行状况指示器,如下所示:

@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/exactor/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;
}

我可以确认已输入此块,并且缓存中确实存在数据

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


共 (1) 个答案

  1. # 1 楼答案

    事实证明,我的对象没有被正确序列化,因此当它在缓存中搜索它们时,找不到它们