使用 Ehcache 3.1,我可以了解当前存储在 ehcache 中的元素的大小以及缓存到目前为止的命中和未命中数。我认为 2.6 有 .getStatistics(),它做类似的事情,但是我在 3.1 版本中很难找到相同的功能。
感谢你的帮助!!
它还没有记录,但有一个缓存统计服务可以为您提供与 EhCache 2.X 中相同的统计信息。我刚刚在最新版本的 EhCache (3.5) 中测试了它。
以下是如何在缓存管理器上配置它的示例:
StatisticsService statisticsService = new DefaultStatisticsService();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(statisticsService)
.build();
cacheManager.init();
Run Code Online (Sandbox Code Playgroud)
然后,当使用了这个管理器提供的缓存后,你可以向统计服务请求统计数据。这是一个小样本:
CacheStatistics ehCacheStat = statisticsService.getCacheStatistics("myCache");
ehCacheStat.getCacheHits();
Run Code Online (Sandbox Code Playgroud)
您可以在 ehcache 的 github 上的单元测试中看到所有这些操作:https ://github.com/ehcache/ehcache3/blob/master/integration-test/src/test/java/org/ehcache/integration/statistics /CacheCalculationTest.java
目前没有公开的统计API。它在路线图上,但我无法向您提供比这更具体的信息。
另一种方法是使用 JCache 集成,它提供一组作为 MBean 公开的标准统计信息。
| 归档时间: |
|
| 查看次数: |
6256 次 |
| 最近记录: |