class Book {
...
static mapping = {
cache true
}
}
快取
目的
為網域類別啟用 Hibernate 第二層快取。
範例
說明
用法:cache(布林值/字串/對應)
引數
-
usage
- 快取使用方式。可以是read-only
、read-write
、nonstrict-read-write
或transactional
-
include
(選用) - 是否包含非延遲關聯。可以是all
或non-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.
}
}
更多資訊請參閱使用者指南中關於 快取 的章節。