【发布时间】:2013-05-13 16:34:18
【问题描述】:
我正在尝试缓存从控制器调用的以下查询:
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) 查询,所以我认为这意味着没有从查询缓存中检索结果?我在本地运行所有内容,因此不可能因为缓存的查询结果已失效(由另一个用户的操作)而丢失缓存。
【问题讨论】:
标签: hibernate caching grails grails-orm