我在我的一个项目中设置了一个缓存,以及自定义运行状况指示器,如下所示:
@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”:{“缓存大小”:9,“缓存命中计数”:0,“缓存未命中计数”:9,“缓存放置计数”:9,“缓存删除计数” :0,"缓存过期计数":0}}
我在其他项目中访问缓存的代码是:
Cacheable cachedResult = CacheManager.getInstance().getCache(request);
if (cachedResult != null)
{
CustomResponse response = (CustomResponse) cachedResult.getObject();
return response;
}
我可以确认该块已被输入并且缓存中确实有数据。
我不知道为什么点击统计没有更新。任何帮助,将不胜感激!
一只名叫tom的猫
相关分类