Grails 中包含惰性和非惰性属性的缓存

kuz*_*uzo 2 orm grails hibernate ehcache associations

Grails 文档指出,

class Person {
    ..
    static mapping = {
        table 'people'
        cache true
    }
}
Run Code Online (Sandbox Code Playgroud)

“将配置一个‘读写’缓存,其中包括惰性和非惰性属性。”

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

static hasMany = [addressess: Address]
Run Code Online (Sandbox Code Playgroud)

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

dma*_*tro 5

默认情况下,关联的处理方式与lazyGrails 中相同。

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

cache usage: 'read-write', include: 'all' //includes lazy and non-lazy
Run Code Online (Sandbox Code Playgroud)

为了仅缓存内部的关联Person,您需要

addresses cache: true

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

cache usage: 'read-write', include: 'non-lazy' 
//usage can be according to the need 'read-only', 'read-write', etc
Run Code Online (Sandbox Code Playgroud)