Reputation: 12406
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?
Upvotes: 1
Views: 228
Reputation: 75671
I'm not sure why it doesn't work, but this is Grails, not PHP - don't do database access in the view.
Upvotes: 2