Creating a Decorator

You can add decorators to a cache either declaratively in the ehcache.xml configuration file, or programmatically.

Declarative Creation

You can configure decorators directly in ehcache.xml. The decorators will be created and added to the CacheManager.

It accepts the name of a concrete class that extends net.sf.ehcache.constructs.CacheDecoratorFactory

The properties will be parsed according to the delimiter (default is comma ",") and passed to the concrete factory's createDecoratedEhcache(Ehcache cache, Properties properties) method along with the reference to the owning cache.

It is configured as per the following example:

   <cacheDecoratorFactory 
        class="com.company.SomethingCacheDecoratorFactory" 
        properties="property1=36 ..." />

Note that decorators can be configured against the defaultCache. This is very useful for frameworks like Hibernate that add caches based on the configuration of the defaultCache.

Programmatic Creation

Cache decorators are created as follows:

BlockingCache newBlockingCache = new BlockingCache(cache);

The class must implement Ehcache.