Michael J. Lee
Michael J. Lee

Reputation: 12406

Grails not using query cache in view

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

Answers (1)

Burt Beckwith
Burt Beckwith

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

Related Questions