如何从二级查询缓存中获取条目?

发布于 2024-09-01 12:24:10 字数 928 浏览 2 评论 0原文

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

我的代码如下:

def getCacheStats() {
  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 cannot be cast to org.hibernate.cache.CacheKey

在谷歌搜索后,我没有找到任何关于如何显示与区域StandardQueryCache关联的缓存查询结果集的条目列表的线索代码> 和 UpdateTimestampsCache

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守护在此方 2024-09-08 12:24:10

它相当复杂,但这应该会让你更进一步。您可以通过 SessionFactory 访问查询缓存,因此假设您可以访问该查询缓存(例如通过“def sessionFactory”),那么您可以像这样访问底层缓存:

def cache = sessionFactory.queryCache
def realCache = [email protected]
def keys = realCache.keys
for (key in keys) {
    def value = realCache.get(key).value
    // do something with the value
}

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

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 = [email protected]
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文