(快速參考)

快取

目的

為網域類別啟用 Hibernate 第二層快取。

範例

class Book {
    ...
    static mapping = {
        cache true
    }
}

說明

用法:cache(布林值/字串/對應)

引數

  • usage - 快取使用方式。可以是 read-onlyread-writenonstrict-read-writetransactional

  • include (選用) - 是否包含非延遲關聯。可以是 allnon-lazy

您可以為每個網域類別啟用快取,例如

static mapping = {
    cache true
}

這將組態網域類別以使用「讀寫」快取,但您可以組態任何適當的快取政策(且受到快取實作支援)

static mapping = {
    cache 'transactional'
}

static mapping = {
    cache usage: 'read-only', include: 'non-lazy'
}

您也可以在每個關聯的基礎上組態快取政策

class Author {

    static hasMany = [books: Book]

    static mapping = {
        books cache: true // or 'read-write' etc.
    }
}

更多資訊請參閱使用者指南中關於 快取 的章節。