I am developing a Java web application that bases it behavior through large XML configuration files that are loaded from a web service. As these files are not actually requi
Bref , you can use this ready spring ehcache configuration
1- ehcache.xml : show global configuration of Ehcache.
2- ehcache-spring.xml : create EhCacheManagerFactoryBean and EhCacheFactoryBean.
3- Inject "myCache" bean in your business class , see the following exemple to get started with getting and putting a object in your cache.
@Resource("myCache")
private net.sf.ehcache.Cache myCache;
@Resource("myService")
private Service myService;
public byte[] getFromCache(final String code)
{
// init Cache
final StringBuilder builder = new StringBuilder();
// key to identify a entry in cache map
final String key = code;
// get form the cache
final Element element = myCache.get(key);
if (element != null && element.getValue() != null)
{
return (byte[]) element.getValue();
}
final byte[] somethingToBeCached = myService.getBy(code);
// store in the cache
myCache.put(new Element(key, somethingToBeCached));
return somethingTobeCached;
}