# Grails 1.1 缓存策略 - 缓存实例

**URL:** <https://www.isharkfly.com/t/grails-1-1/6633>\
**Category:** 程序语言\
**Created:** [November 4, 2012, 3:41pm UTC](https://www.isharkfly.com/t/grails-1-1/6633 "2012-11-04T15:41:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [November 4, 2012, 3:41pm UTC](https://www.isharkfly.com/t/grails-1-1/6633/1 "2012-11-04T15:41:06Z")

</div>

假如要在映射代码块中启用缺省的缓存，可以通过调用 cache 方法实现:`class Person {
	..
	static mapping = {
		table 'people'
		cache true
	}
}`上面的例子中将配置一个读-写(read-write)缓存包括lazy和non-lazy属性.假如你想定制这些特性，你可以如下所示:`class Person {
	..
	static mapping = {
		table 'people'
		cache usage:'read-only', include:'non-lazy'
	}
}`
