Sami
Sami

Reputation: 51

how can I obtain grails hibernate L2 cache statistics?

grails hibernate L2 cache statistics - net.sf.ehcache.Statistics

I am using ehcache with my L2 cache.

I want to profile the performance and obtain statistics from net.sf.ehcache.Statistics. Without any success, I have been searching for a way to access the L2 cache manager from Grails or Spring.

I appreciated any hint.

Bellow are typical hibernate settings used

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
}

Upvotes: 2

Views: 938

Answers (2)

jeha
jeha

Reputation: 10750

Simply add generate_statistics=true to your Hibernate settings:

hibernate {
    ...
    generate_statistics=true
    ...
}

Upvotes: 1

David Genn
David Genn

Reputation: 709

You can get hold of the sessionFactory by having it injected into your service and then enable statistics on it:

class My Service {

  def sessionFactory

  def myMethod() {
    // Enable stats
    Statistics stats = sessionFactory.getStatistics();
    stats.setStatisticsEnabled(true);

   // Do some querying and analyse the stats

  }

}

Upvotes: 1

Related Questions