Grails 文档指出,
class Person {
..
static mapping = {
table 'people'
cache true
}
}
“将配置一个‘读写’缓存,其中包括惰性和非惰性属性。”
如果我们在 Person 中有一对多关系,例如:
static hasMany = [addressess: Address]
grails 是否将其视为惰性属性? Address 对象是否也被缓存,或者只有与给定 Person 相关的 id 被保留在缓存中?
最佳答案
默认情况下,关联在 Grails 中被视为惰性
。
在上述 Person
的特定示例中,所有
地址对象都将被缓存。上面的默认缓存设置可以扩展为如下所示:
cache usage: 'read-write', include: 'all' //includes lazy and non-lazy
为了仅缓存 Person
内的关联,您需要
地址缓存:true
为了放弃 Person
中缓存的关联,您需要
cache usage: 'read-write', include: 'non-lazy'
//usage can be according to the need 'read-only', 'read-write', etc
关于hibernate - Grails 中包含惰性和非惰性属性的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18471419/