Product Documentation : Ehcache Recipes : Using Grails and Ehcache
Using Grails and Ehcache
Grails 1.2RC1 and higher use Ehcache as the default Hibernate second level cache. However earlier versions of Grails ship with the Ehcache library and are very simple to enable. The following steps show how to configure Grails to use Ehcache. For 1.2RC1 and higher, some of these steps are already done for you.
Configuring Ehcache As the Second Level Hibernate Cache
Edit DataSource.groovy as follows:
hibernate {
Overriding Defaults
As is usual with Hibernate, it will use the defaultCache configuration as a template to create new caches as required. For production use you often want to customize the cache configuration. To do so, add an ehcache.xml configuration file to the conf directory (the same directory that contains DataSource.groovy). A sample ehcache.xml which works with the Book demo app and is good as a starter configuration for Grails is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi=""
xsi:noNamespaceSchemaLocation="ehcache.xsd" >
<diskStore path="/path/to/store/data"/>
<cacheManagerEventListenerFactory class="" properties=""/>
<persistence strategy="none"/>
<cache name="Book"
<cache name="org.hibernate.cache.UpdateTimestampsCache"
<cache name="org.hibernate.cache.StandardQueryCache"
Springcache Plugin
The Springcache plugin allows you to easily add the following functionality to your Grails project:
*Caching of Spring bean methods (typically Grails service methods).
*Caching of page fragments generated by Grails controllers.
*Cache flushing when Spring bean methods or controller actions are invoked.
The plugin depends on the Ehcache and Ehcache-Web libraries. See Springcache Plugin, a part of the Grails project, for more information.
Clustering Web Sessions
This is handled by Terracotta Web Sessions. See this blog for a great introduction on getting this going with Grails and Tomcat.
Copyright © 2010-2015 Software AG, Darmstadt, Germany.

Product Logo |   Feedback