(Quick Reference)

cache

目的
Purpose

Enables the Hibernate second-level cache for the domain class.

使用例
Examples

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

詳細
Description

Usage: cache(boolean/string/map)
使用方法:
Usage:
cache(boolean/string/map)

引数:

Arguments:
  • usage - The cache usage. Can be read-only, read-write, nonstrict-read-write or transactional
  • include (optional) - Whether to include non-lazy associations. Can be all or non-lazy

You enable caching per domain class, for example:

static mapping = {
    cache true
}

This will configure the domain class to use a 'read-write' cache, but you can configure whatever cache policy is appropriate (and supported by the cache implementation):

static mapping = {
    cache 'transactional'
}

or

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

You can also configure the cache policy on a per-association basis:

class Author {

static hasMany = [books: Book]

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

For more information see the section on Caching in the user guide.