【问题标题】:Cache that includes both lazy and non-lazy properties in GrailsGrails 中同时包含惰性和非惰性属性的缓存
【发布时间】:2013-08-30 13:17:25
【问题描述】:

Grails 文档指出,

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

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

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

static hasMany = [addressess: Address]

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

【问题讨论】:

    标签: hibernate grails orm associations ehcache


    【解决方案1】:

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

    在上述Person 的特定示例中,all 地址对象将被缓存。上面的默认缓存设置可以展开如下:

    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
    

    【讨论】:

    • 我安装了 grails melody 插件,我可以在其中检查 ehcache 中的内容。像在 grails 文档中那样完成映射 - 只是“缓存真”我可以在旋律 raport 中看到人员缓存,但没有地址缓存。如果,你写的是真的,为什么我看不到地址缓存?
    猜你喜欢
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    相关资源
    最近更新 更多