grails hibernate L2 缓存统计信息 - net.sf.ehcache.Statistics
我正在将 ehcache 与 L2 缓存一起使用。
我想分析性能并从 net.sf.ehcache.Statistics 获取统计信息。 但没有成功,我一直在寻找一种从 Grails 或 Spring 访问 L2 缓存管理器的方法。
我很感激任何提示。
以下是使用的典型 hibernate 设置
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
}
最佳答案
您可以通过将 sessionFactory
注入(inject)到您的服务中来获取它,然后 enable statistics关于它:
class My Service {
def sessionFactory
def myMethod() {
// Enable stats
Statistics stats = sessionFactory.getStatistics();
stats.setStatisticsEnabled(true);
// Do some querying and analyse the stats
}
}
关于hibernate - 如何获取 grails hibernate L2 缓存统计信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11621495/