I have cached some domain instances and queries in my grails application. I would expect that after the first time the queries are fired to db, the subsequent calls will only hit cache.
But, I am seeing that periodically the queries hit db (after every 5-6 times). No data is getting updated/inserted into database in the mean time. I am using p6spy to check out all the queries that are logged and do not see any updates or inserts happening.
Is there any additional settings I need to tweek?
Currently domain class has
static mapping = {
cach true
}
Queries like findBy* have the [cache:true] set.
If you don’t configure Ehcache, your caches will use the default timeout of 120 seconds. See http://ehcache.org/ehcache.xml for a well-commented example file that’s the same as the default file that’s in the Ehcache jar.
You can configure timeouts, max elements in memory, whether to spill over to disk, etc. by creating an ehcache.xml in your application. Put it in src/java and it will be copied into the classpath, and Ehcache will see it and use yours instead of its defaults.