【问题标题】:Grails 3.0.9. How can I test Hibernate second level caching?圣杯 3.0.9。如何测试 Hibernate 二级缓存?
【发布时间】:2016-02-01 07:55:51
【问题描述】:

如何测试 Hibernate 二级缓存?

我尝试在 application.yml 中配置它:

hibernate:
cache:
    use_second_level_cache: true
    provider_class: net.sf.ehcache.hibernate.EhCacheProvider
    region:
        factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
flush:
    mode: 'commit'

跟踪选项dataSource { ... logSql = true },总是显示执行SQL?或者还包括从二级缓存中提取而不执行SQL?

【问题讨论】:

    标签: hibernate grails grails-3.0


    【解决方案1】:

    我猜你可以激活 org.hibernate.cache category 来记录所有二级缓存活动。

    为此,请编辑您的 Config.groovy 文件。找到以下行:

    hibernate = "off"
    

    并将其替换为:

    hibernate.cache = "trace,stdout"
    

    你也可以看看 grails FAQ 这个。

    编辑:统计 API 的使用

    要浏览二级缓存区域或查询缓存区域的内容,请使用 Statistics API:

    Map cacheEntries = sessionFactory.getStatistics()
        .getSecondLevelCacheStatistics(regionName)
        .getEntries();
    

    您将需要启用统计信息,并且可以选择强制 Hibernate 以更易读的格式保存缓存条目:

    hibernate.generate_statistics true
    hibernate.cache.use_structured_entries true
    

    希望这会有所帮助!谢谢

    【讨论】:

    • 唉,放置在 Grails 3.0 其他配置中
    • 我已经编辑了我的答案并添加了一些关于统计 API 的信息,希望对您有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2015-05-14
    • 2010-11-16
    • 2014-11-28
    • 2011-12-18
    • 2012-12-12
    • 2016-05-10
    • 2014-03-15
    • 2010-10-16
    相关资源
    最近更新 更多