如何获得grails hibernate二级高速缓存统计信息?
问题描述:
grails hibernate二级高速缓存统计 - net.sf.ehcache.Statistics如何获得grails hibernate二级高速缓存统计信息?
我正在使用ehcache和我的二级高速缓存。
我想剖析性能并从net.sf.ehcache.Statistics获取统计信息。 没有成功,我一直在寻找一种从Grails或Spring访问L2缓存管理器的方法。
我赞赏任何提示。
贝娄是用于
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
format_sql = true
use_sql_comments = true
}
答
你可以让它在它注入到你的服务,然后enable statistics得到sessionFactory
的保持典型的休眠设置:
class My Service {
def sessionFactory
def myMethod() {
// Enable stats
Statistics stats = sessionFactory.getStatistics();
stats.setStatisticsEnabled(true);
// Do some querying and analyse the stats
}
}
答
只需添加generate_statistics=true
到你的Hibernate设置:
hibernate {
...
generate_statistics=true
...
}
谢谢,我哈我发现“stats.getSecondLevelCacheRegionNames()”只返回“StandardQueryCache,UpdateTimestampsCache”。 我正在寻找正确的地方来验证我的L2缓存吗? 贝娄是我的域名映射。 类LogCauseMemento { 静态映射= { 版假 id生成: '分配' 表 'log_cause' 缓存:真 }} 贝娄是域条目ehcache.xml中。 – Sami 2012-07-24 18:03:36
Hibernate文档是在这个好(HTTP://docs.jboss .ORG /休眠/ ORM/3.3 /参考/ EN/HTML/performance.html#性能的缓存)。您可以调用'sessionFactory.getStatistics() .getSecondLevelCacheStatistics(regionName) .getEntries();'通过调用'getSecondLevelCacheRegionNames()'找到'regionName'手杖' – 2012-07-25 06:22:40