繁体   English   中英

不使用Grails查询缓存

[英]Grails query cache is not used

我正在尝试缓存从控制器调用的以下查询:

def approvedCount = Book.countByApproved(true, [cache: true])

通过添加以下内容,我为Book类启用了二级缓存

static mapping = {
    cache true
}

Book.groovy 我还在DataSource.groovy配置了以下内容

hibernate {
  cache.use_second_level_cache = true
  cache.use_query_cache = true
  cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}

在同一文件中,我通过在dataSource块中添加logSql=true来启用查询日志记录。

每次加载页面时, Book.countByApproved(true)记录Book.countByApproved(true)查询,因此我认为这意味着没有从查询缓存中检索结果吗? 我在本地运行所有内容,因此不可能丢失缓存,因为缓存的查询结果已无效(由另一个用户的操作)。

我将看一下您提交的JIRA问题 ,但是由于HQL起作用,因此它看起来像是动态查找程序的问题:

Book.executeQuery(
   'select count(*) from Book where name=:name',
   [name: 'foo'], [cache: true])

和条件查询一样:

def count = Book.createCriteria().count {
   eq 'name', 'foo'
   cache true
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM