Plugins You can find out about all the publicly available Grails plugins.

Distributed Ehcache

  • Tags: cache
  • Latest: 0.5
  • Last Updated: 16 May 2010
  • Grails version: 1.2.1 > *
  • Authors: glenn.saqui
6 votes
compile "org.grails.plugins:dist-ehcache:0.5"




grails install-plugin dist-ehcache


Distributed Ehcache

This plugin makes it easier to have ehcache as a distributed caching solution. The main driver for this plugin was to have ehcache be used as a distributed hibernate second level cache. The plugin installs an ehcache xml file that has three caches already configured inside. These should always be there but more can be added as the user sees fit.

Caches provided by the distributed cache

  • Distributed cache - A generic cache that can be used to distribute any content across all members of the cluster
  • Local cache - A generic cache that is specific to the individual jvm that the instance of grails runs on
  • Distributed query cache - The distributed hibernate second level query cache
  • Default distributed cache - This is the cache that ehcache uses when it has to create any new caches. This is normally done by plugins or services.


The cache service can be easy injected into any class and offers the following methods:
  • def cache(Serializable key, boolean isCacheDistributed, Closure callable) - A cache method that takes a key and if it should be distributed or not and a closure. The method returns the output from the closure. If the output of the closure was already in the cache it will be returned else the new output will be added to the cache and returned.
  • void put(Serializable key, boolean isCacheDistributed, def value) - Adds the key and value to the local/distributed cache
  • def get(Serializable key, boolea isCacheDistributed) - Returns the value of the key'd item in the cache.
  • void clearQueryCache() - Clears the query cache. This is really useful for testing.
  • void clearLocalCache() - Clears the local cache.
  • void clearDistCache() - Clears the distributed cache.


This tag lib allows the user to cache the body of the tag.
<cache:text key="key" isDist="true">


Controller that can be used to get information about the cache plugin. It gives information on the current environment, the current grails version, the cache peers that the ehcache sees, the current ip address, number of items in the query cache, number of items in the local cache, and the number of items in the distributed cache.


Map of hostname to a comma separated list of properties that are applied to the peer listeners. If the hostname does not match any of the keys it will use the default configuration. To see the default configuration look in the ehcache.xml file that is supplied by the plugin. Look at the section describing CacheManagerPeerListener. Possible values that can be added to the properties are the following: hostName=fully_qualified_hostname_or_ip, port=40001, remoteObjectPort=40002, socketTimeoutMillis=120000"

An example might look like the following:'london':"hostName=", 'vancouver': "hostName=vancouverbe.interface, remoteObjectPort=50002" (+)

The box that has a hostname of london will use the default port (40001), remoteObjectPort (40002), and socketTimeoutMillis (120000) while the box with a hostname of vancouverbe.interface will use a port (40001), remoteObjectPort of 50002 and the default socketTimeoutMillis.