如何测试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的二级缓存中的摘要?
最佳答案
我猜您可以激活org.hibernate.cache category来记录所有第二级缓存 Activity 。
为此,请编辑您的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
希望这可以帮助!谢谢
关于hibernate - Grails 3.0.9。如何测试Hibernate二级缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33460577/