I found some stuff.
I put some trace in com.googlecode.ehcache.annotations.impl.CacheStaticMethodMatcherPointcut.matches(Method method, Class<?> targetClass) like :
public boolean matches(Method method, Class<?> targetClass) {
boolean ret = AdviceType.NONE != this.cacheAttributeSource.getAdviceType(method, targetClass);
if ( targetClass.getCanonicalName().endsWith("LdapManagerImpl")){
System.out.println(targetClass + " : " + method + " = " + ret);
}
return ret;
}
When running, I have two trace :
LdapManagerImpl : findUserFromDn = true
LdapManagerImpl : getGroups = false
What is getGroups() ? it is a function which return a List<Group> the user belong. The getGroups() make a findGroupFromDn call on each DN of groups I got from the User object (List <String> user.memberof.getgroups()).
and after , I have all my findGroupFromDn() traces.
So, the pointcut does not reach the findGroupFromDn() method, only the the getGroups() method (his parent). If I add a @Cacheable on the getGroups() method, all are working, Group object return by the getGroups() are put in Cache, and a second call of getGroups() with same parameters look for result in cache (no more findGroupFromDn call).
Is it normal that a function called by another in the same class is not cacheable ? if I understand, Spring intercept only method call from another class ? (my action class call findUserFromDn and getGroups(), not findGroupFromDn()). For information, if a make a call on findGroupFromDn() from my action class, the trace show me : LdapManagerImpl : findGroupFromDn = true (so pointcut match)
here my ldapManagerImpl code :
@Override
@Cacheable(cacheName = CACHE_NAME_USER)
public User findUserFromDn(String dn) {
try {
System.out.println("findUserFromDn(" + dn + ")");
return ldap.findUserFromDn(dn);
} catch (Exception e) {
return null;
}
}
@Override
@Cacheable(cacheName = CACHE_NAME_GROUP)
public Group findGroupFromDn(String dn) {
try {
System.out.println("findGroupFromDn(" + dn + ")");
return ldap.findGroupFromDn(dn);
} catch (Exception e) {
return null;
}
}
@Override
@Cacheable(cacheName = CACHE_NAME_GROUP)
public List<Group> getGroups(User u) {
List<Group> groupes = new ArrayList<Group>();
for (String dn : u.getMemberOf().getGroups()) {
Group g = this.findGroupFromDn(dn);
if (g != null) {
groupes.add(g);
}
}
return groupes;
}
Thanks