(Quick Reference)



Renders a GSP template and caches the result so that the next time the same template is rendered it doesn't have to be evaluated again. Optionally, a key may be provided which can be helpful if the cached content is different per user, for example.

This tag behaves just like the g:render tag provided by Grails except this one caches the rendered result so the template doesn't have to be re-evaluated each time it is rendered.

By default the key used in the cache is the path to the template. If the same template is rendered multiple times with a different model, an explicit key should be provided, otherwise the separate invocations (with different models) will share the same cache entry.

<cache:render template="myTemplate" model="[user: currentUser]" key="${currentUser.id}"/>

Note that the key's namespace is confined to a particular template. This means that if there are 2 separate GSP templates cached with the same key value, the 2 will not collide with each other. Each cached GSP template has its own set of keys.


<cache:render template="myTemplate" model="[name: 'Some Value']"/>

<cache:render template="myTemplate" model="[name: 'Some Value']" key="${currentUser.id}"/>

<cache:render template="myTemplate" model="[name: 'Some Value']" key="${currentUser.id}" ttl="${60*60*24*7}" />


  • template (required) - The name of the template to apply
  • key (optional) - An optional key that may be provided to allow for different instances of the rendered template to be held in the cache, presumably with different content.
  • contextPath (optional) - the context path to use (relative to the application context path). Defaults to "" or path to the plugin for a plugin view or template.
  • bean (optional) - The bean to apply the template against
  • model (optional) - The model to apply the template against as a java.util.Map
  • collection (optional) - A collection of model objects to apply the template to
  • var (optional) - The variable name of the bean to be referenced in the template
  • plugin (optional) - The plugin to look for the template in
  • ttl (optional) - An optional ttl (seconds) may be provided to allow the blocks to automatically evict a specified number of seconds after first insertion.

See the documentation for the core g.render tag for details on each of the optional attributes.