如何从第二级查询缓存中获取条目? [英] How to get entries from the second level query cache?

查看:122
本文介绍了如何从第二级查询缓存中获取条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 grails 应用程序中,我想要显示所有二级目前的条目来自所有地区的缓存



我的代码如下:

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

然而,只要区域名称是一切正常而不是> org.hibernate.cache.StandardQueryCache (用于查询缓存)。在这种情况下,抛出一个异常:

  java.lang.ClassCastException:org.hibernate.cache.QueryKey不能转换为org.hibernate.cache.CacheKey 

通过使用Google搜索,我没有发现任何关于如何显示与区域 StandardQueryCache UpdateTimestampsCache 关联的缓存查询结果集的条目列表

你能帮我找到解决方案吗?

解决方案

<这是相当复杂的,但这应该让你更进一步。你可以通过SessionFactory访问查询缓存,所以假设你可以访问它(例如通过'def sessionFactory'),那么你可以像这样访问底层缓存:

  def cache = sessionFactory.queryCache 
def realCache = cache.region。@ underlyingCache.backingCache
def keys = realCache.keys
for(key in keys ){
def value = realCache.get(key).value
//用
做一些事情

请注意,这些值将是一个Long值列表。我不确定第一个表示的是什么(这是一个很大的值,例如5219682970079232),但剩下的就是缓存的域类实例的ID。


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?

解决方案

It's fairly complicated but this should get you further. You can access the query cache via the SessionFactory, so assuming you have access to that (e.g. via 'def sessionFactory') then you can get to the underlying caches like this:

def cache = sessionFactory.queryCache
def realCache = cache.region.@underlyingCache.backingCache
def keys = realCache.keys
for (key in keys) {
    def value = realCache.get(key).value
    // do something with the value
}

Note that the values will be a List of Long values. I'm not sure what the first one signifies (it's a large value, e.g. 5219682970079232), but the remaining are the IDs of the cached domain class instances.

这篇关于如何从第二级查询缓存中获取条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆