1

Grails 文档指出,

class Person {
    ..
    static mapping = {
        table 'people'
        cache true
    }
}

“将配置一个包含惰性和非惰性属性的‘读写’缓存。”

如果我们在 Person 中有一对多的关系,例如:

static hasMany = [addressess: Address]

grails 是否将其视为惰性属性?Address 对象是否也被缓存,或者只有与给定 Person 相关的 id 被保存在缓存中?

4

1 回答 1

3

默认情况下,关联被视为lazy在 Grails 中。

在上面的特定示例中Personall地址对象将被缓存。上面的默认缓存设置可以扩展为如下所示:

cache usage: 'read-write', include: 'all' //includes lazy and non-lazy

为了只缓存里面的关联Person,你需要

addresses cache: true

为了从缓存中丢弃关联Person,您需要

cache usage: 'read-write', include: 'non-lazy' 
//usage can be according to the need 'read-only', 'read-write', etc
于 2013-08-27T17:21:16.037 回答