cache

Purpose

Enables the configuration of the Hibernate second-level cache.

Examples

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

Description

Usage: cache(boolean/string/map)

Arguments:

In order to take advantage of the Hibernate second-level cache you explicitly need to 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:

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.