I was quite disappointed on the documentation and example on GORM domain documentation and caching configuration.
Here are my conclusion, relying on a specific Postgresql schema mapping.
Configure Id generation
I wanted to generate my pk according to 2 strategies depending on the domain usage :- Auto increment per table
- Sequences
static mapping ={
id generator: 'sequence', params: [sequence: 'SEQ_NAME', schema: 'schema']
}
static mapping = {
id generator: 'increment', params: [schema: 'schema']
}
Configure caching
Being used to ehcache configuration region, here is the configuration on my cached domain :Domain.groovy (change read-write with your need) :
static mapping = {
cache usage: 'read-write', region: 'myregion'
}
Config.groovy :
grails.cache.config = {
cache {
name 'myregion' // max 12h
timeToIdleSeconds 3600 // expire after an hour without usage
timeToLiveSeconds 43200 // expire after 12 hours anyway
maxElementsInMemory TODO
}
}
And don't forget to configure the cache in Datasource.groovy:hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
}
And in BuildConfig.groovy :
dependencies{
compile "net.sf.ehcache:ehcache-core:2.4.6"
}
plugins {
compile ":cache:1.1.1
}
0 commentaires:
Enregistrer un commentaire