【问题标题】:See cache's hit and misses查看缓存的命中和未命中
【发布时间】:2014-09-10 15:58:27
【问题描述】:

我正在使用启用了二级缓存的 Hibernate 和 ehcache。我将@Cacheable 放在我的用户实体上,如下所示:

@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "usersCache")
public class User extends AbstractEntity {

...


}

但是当我启用 Hibernate 的 sql 日志记录时,我仍然看到我的 `select * from users where userId = ?" 查询...我想这可能是正常行为,缓存过程对 Hibernate 是透明的,这只是查询然后 ehcache 拦截它并从缓存中获取数据......那么我如何查看查询是命中还是未命中?

【问题讨论】:

    标签: java hibernate caching


    【解决方案1】:

    您可以通过设置hibernate.generate_statistics property to true 来启用Hibernate statistics generation。然后您可以通过SessionFactory.getStatistics() 监控缓存命中/未命中计数。

    SessionFactory.getStatistics().getSecondLevelCacheStatistics()
    

    提供此信息。

    也可以通过JConsole看到,参考this

    【讨论】:

      猜你喜欢
      • 2012-04-21
      • 2021-01-12
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      相关资源
      最近更新 更多