Java Cache Tutorial with Cache Dependency Injection (CDI)
From Resin 4.0 Wiki
<web-app xmlns="http://caucho.com/ns/resin" xmlns:ee="urn:java:ee" xmlns:resin="urn:java:com.caucho.resin"> <resin:ClusterCache ee:Named="my-cache"/> </web-app>
import javax.inject.Inject; import javax.cache.Cache; public class MyService { @Inject @Named("my-cache") private Cache<String,String> _cache; public String doStuff(String key) { String cachedValue = _cache.get(key); if (cachedValue == null) { cachedValue = doLongCalculation(key);
_cache.put(key, cachedValue); } return cachedValue; } }