Dón*_*nal 4 grails caching hibernate grails-orm
我正在尝试缓存从控制器调用的以下查询:
def approvedCount = Book.countByApproved(true, [cache: true])
Run Code Online (Sandbox Code Playgroud)
我Book通过添加为该类启用了二级缓存
static mapping = {
cache true
}
Run Code Online (Sandbox Code Playgroud)
到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'
}
Run Code Online (Sandbox Code Playgroud)
在这同样的文件我已通过添加启用查询日志logSql=true的dataSource块。
每次加载页面时,Book.countByApproved(true)都会记录查询,所以我认为这意味着没有从查询缓存中检索结果?我在本地运行所有内容,因此不可能因为缓存的查询结果已失效(由另一个用户的操作)而错过缓存。
我会看看你提交的JIRA 问题,但它看起来像是动态查找器的问题,因为 HQL 有效:
Book.executeQuery(
'select count(*) from Book where name=:name',
[name: 'foo'], [cache: true])
Run Code Online (Sandbox Code Playgroud)
和标准查询一样:
def count = Book.createCriteria().count {
eq 'name', 'foo'
cache true
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2411 次 |
| 最近记录: |