"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/cache.html" (14 Sep 2022, 61195 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(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)

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.