Grails在视图中不使用查询缓存 [英] Grails not using query cache in view
问题描述
我在关于grails中的查询缓存以及它的调用方面发现了一个奇怪的问题。我已经测试了几次并得到了相同的结果。
问题:下面的view \gsp代码每次都碰到数据库,即使我有 cache:true
on。
< g:select name =foo.thing.idin =$ {Thing.findAll([cache:true])}value =$ {foo.thing?.id}/>
解决方法:将查询调用推入控制器要考虑 cache:true
参数,它现在停止在每个页面加载时触击数据库。
控制器:
def doStuff = {
def things = Thing.findAll([cache:true]);
return ['things':things]
}
p>
< g:select name =foo.thing.idin =$ {things}value =$ {foo .thing?.id}/>
我使用Grails 1.3.7,配置如下:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class ='org。 hibernate.cache.EhCacheProvider'
}
是否有其他人看过或可以看到向我介绍它为什么会以不同的方式工作? 我不确定为什么它不起作用,但这是Grails,而不是PHP--不要在视图中访问数据库。
I've found an odd issue regarding the query cache in grails and where it's called. I've tested this several times and got the same result.
Problem: The bellow view\gsp code hits the database every time even though i have cache:true
on.
<g:select name="foo.thing.id" in="${Thing.findAll([cache:true])}" value="${foo.thing?.id}" />
Workaround: Pushing the query call into the controller respects the cache:true
argument and it now stops hitting the database on every page load.
Controller:
def doStuff = {
def things = Thing.findAll([cache:true]);
return ['things':things]
}
View:
<g:select name="foo.thing.id" in="${things}" value="${foo.thing?.id}" />
I'm using Grails 1.3.7 with the following config....
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='org.hibernate.cache.EhCacheProvider'
}
Has anyone else seen this or can describe to me why it would work differently?
I'm not sure why it doesn't work, but this is Grails, not PHP - don't do database access in the view.
这篇关于Grails在视图中不使用查询缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!