java - How to get entries from the second level query cache? -


In my application, I want to display all existing entries of the second level cache from all areas .

My code is as follows:

  def getCacheStats () {StatisticsImpl stats = for sessionFactory.statistics (region.secondLevelCacheRegionNames in area names) {log.debug stats .getSecondLevelCacheStatistics ( Field name) .entries}}  

Although the name of all the fields is not org.hibernate.cache.StandardQueryCache (for field use In that case, an exception is thrown:

  java.lang.ClassCastException: org.hibernate.cache.QueryKey can not be entered on org.hibernate.cache.CacheKey  

Googling around, let me < Strong> StandardQuery cache and update timestamp cache to display the list of entries.

Can you please help me find a solution for this?

This is quite complex, but you should proceed with this. You can access the query cache through the sessionfix, so assume that you have access to it (for example 'def sessionFactory'), you can get the underlying cache like this:

  def cache = sessionFactory .key cache def realCache = cache.region @ UnderlyingCache.backingCache def keys = to realCache.keys (Key key) {def value = realCache.get (key) with some .value // value}  

Note That value will be a list of long values. I'm not sure that the first one is a symbol (this is a big value, for example 521 9 682970079232), but there are examples of the remaining cached domain classes.


Comments