Hi
If using Spring 3.0, or better 3.1, forgot Spring annotations for ehcache and use Spring caching. I think this google project won't last too much. It works fine, but the Spring feature committment is stronger than google-code one.
Notice that the "clever" Spring people has decided that the default key generator for the caching does not take into account the function name. So... If you have two functions with the same argument signature to be cached in the same cache, they will clash. You will have to create your own key generator.
this in the app context file:
<cache:annotation-driven key-generator="keyCacheGenerator" />
<bean id="keyCacheGenerator" class="liba.KeyCacheGenerator" />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="default" />
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="imex" />
</set>
</property>
</bean>
and this is one possible key generator source:
package liba;
import java.lang.reflect.Method;
import org.springframework.cache.interceptor.KeyGenerator;
public class KeyCacheGenerator implements KeyGenerator {
@Override
public Object generate(Object arg0, Method arg1, Object... arg2) {
String a = arg1.getName() + "@;#";
for (Object o : arg2) {
if (o == null)
a += "&nulo&";
else {
a += o.getClass().getName() + "$" + o.toString();
}
a += "--.";
}
return a;
}
}
Regards. And don't forget to follow the Spring instructions about caching support