EHC ❯ Configuration templates
-
New Feature
-
Status: Open
-
2 Major
-
Resolution:
-
ehcache-core
-
-
prodmgmt
-
Reporter: jkronegg
-
August 26, 2011
-
1
-
Watchers: 3
-
May 06, 2013
-
Attachments
Description
It would be very practical to have the notion of cache template (or model) in ehcache configuration XML file.
By now, we write something like this in ehcache.xml :
<ehcache>
<cache name="myCache1" maxElementsInMemory="0" maxElementsOnDisk="0" eternal="true" copyOnWrite="false" overflowToDisk="false" diskPersistent="true">
<cache name="myCache2" maxElementsInMemory="0" maxElementsOnDisk="0" eternal="true" copyOnWrite="false" overflowToDisk="false" diskPersistent="true">
...
<cache name="myCacheN" maxElementsInMemory="0" maxElementsOnDisk="0" eternal="true" copyOnWrite="false" overflowToDisk="false" diskPersistent="true">
</ehcache>
The idea is to have something like:
<ehcache>
<cache name="myCache1" maxElementsInMemory="0" maxElementsOnDisk="0" eternal="true" copyOnWrite="false" overflowToDisk="false" diskPersistent="true">
<cache name="myCache2" template="myCache1">
...
<cache name="myCacheN" template="myCache1">
</ehcache>
This would make the ehcache.xml much more readable and will make configuration much easier. You can imagine having a few cache template (e.g. one for ehcache standalone, one for ehcache with jgroups replication, one for ehcache with Terracotta) and a lot of cache stores relying on these templates.
The benefits:
- easier configuration file maintenance (changing a template will change all cache store configuration that use it)
- faster configuration understanding by new developpers (less configuration to read means faster understanding)
- lower memory usage (if all cache use the same CacheConfiguration and not a clone; I don’t know it this is possible, especially regarding listeners, peers, threads and so on)
This would only require to modify *net.sf.ehcache.config.CacheConfiguration* as such:
- add a “copyParameters(CacheConfiguration)” method (based on the “clone()” method)
- add a “template” field
- add a “template” setter which do something like:
public CacheConfiguration template(String templateName) {
CacheConfiguration templateConfig = CacheManager.getConfiguration().getCacheConfigurations().get(templateName);
if (templateConfig==null) {
throw new CacheException("Cache with name '"+templateName+"' does not exist and cannot be used as template");
}
copyParameters(templateConfig);
return this;
}
Sharing the template cache CacheConfiguration for all caches that use it may be complex, so it would probably be a nice-to-have (e.g. boolean field “sharedConfiguration”).
Note that the feature request CDV-1328 has a similar title but requests a different feature: having pre-configured templates.
Comments
Julien Kronegg 2011-09-30
Julien Kronegg 2011-10-07
Updated patch (XSD file now validate the ehcache.xml properly), as ehcache-EHC878-patch-2.zip
I implemented the template cache configuration and provided the patch.
The {{net.sf.ehcache.config.CacheConfiguration}} class was changed as such:
The {{net.sf.ehcache.config.Configuration}} class was changed as such:
The {{ehcache.xsd}} was changed as such:
Shared template (i.e. having one single {{CacheConfiguration}} instead of N for N cache that are using template) was not implemented. This would require to :
The zip file (ehcache-EHC878-patch-1.zip) contains the patch (diff file) and the full files.