How to get entries from the second level query cache ?

Posted by fabien7474 on Stack Overflow See other posts from Stack Overflow or by fabien7474
Published on 2010-05-15T21:51:18Z Indexed on 2010/05/15 22:50 UTC
Read the original article Hit count: 360

In my grails application, I want to display all the current entries of the second-level cache from all regions.

My code is as following :

def getCacheStats() {
  StatisticsImpl stats = sessionFactory.statistics
  for (regionName in stats.secondLevelCacheRegionNames) {
    log.debug stats.getSecondLevelCacheStatistics(regionName).entries
  }
}

However everything works fine as long as the region name is not org.hibernate.cache.StandardQueryCache (region used for Query Cache). In that case, an exception is thrown :

java.lang.ClassCastException: org.hibernate.cache.QueryKey cannot be cast to org.hibernate.cache.CacheKey

Having googling around, I didn't find any clues about how to display the list of entries of the cached query result sets associated with regions StandardQueryCache and UpdateTimestampsCache.

Could you please help me find a solution for this?

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about grails