I'm trying to cache the following query that is called from a controller:
def approvedCount = Book.countByApproved(true, [cache: true])
I have enabled the 2nd-level cache for the Book class, by adding
static mapping = {
cache true
}
to Book.groovy. I also have the following configured in DataSource.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 the dataSource block.
Every time I load the 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 result has been invalidated (by the actions of another user).