I can't get the idea of the AOP example code in page 367.
Code:
public PixUser lookup(ProceedingJoinPoint call, String userName) {
log.debug(âAdvising method: ââ + call.getSignature().toShortString());
PixUser user = (PixUser) cache.get(userName);
if (user != null) {
user = call.proceed();
}
cache.put(user.getUserName());
return user;
}
I presume the idea is first look the cache for the user object by userName and if not found there, fetch user with the target method and put it in the cache. To me it seem this code does the opposite: if the user IS FOUND in the cache (user != null) then the target method is called (call.procees()) and user is fetched from the database. And regardless of the user was in the cache or not, it is put there again.
Instead, shouldn't it be like this
Code:
PixUser user = (PixUser) cache.get(userName);
if (user == null) {
user = call.proceed();
cache.put(user.getUserName());
}
return user;
Or did I understand it all wrong?