I'm trying to post the following question, but get the
This post does not meet our quality standards
error, with no explanation of what the problem is
Title
Grails query cache being ignored
Body
I have an application which is read-mostly, so most of my queries use the Hibernate 2nd-level query cache. I have one query that must be executed every time a page loads, so I invoke it from the layout GSP like this:
${Book.countByApproved(true, [cache: true])}
I have enabled the 2nd-level cache for the
Book
class, by addingstatic mapping = { cache true }
to
Book.groovy
. I also have the following configured inDataSource.groovy
hibernate { cache.use_second_level_cache = true cache.use_query_cache = true cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' }
In this same file I've enabled query logging by adding
logSql=true
in thedataSource
block.Every time I load a page, the
Book.countByApproved(true)
query is logged, so I assume this means that the results are not being retrieved from the query cache? I'm running everything locally, so there's no possibility that the cache is being missed because the cached query results have expired.I don't know if this is relevant, but I'm using the Hibernate Filters plugin and have a default filter configured for the
Book
class. Perhaps there's some issue with using hibernate filters and the query cache?
being
as being (ha) a proper verb.