Distributed Ehcache
Dependency :
compile ":dist-ehcache:0.5"
Summary
Installation
grails install-plugin dist-ehcache
Description
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.
CacheService
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.
CacheTagLib
This tag lib allows the user to cache the body of the tag.<cache:text key="key" isDist="true"> ${sleep(10000)} </cache:text>