请教高手,问题如下:/**
 * 好友管理类
 */
public class FridServ{
     //利用spring注解缓存用户的好友列表
     @Cacheable(value="fridsCache",key="#uid")
     public List<Frid> getFrids(long uid)
     {
         return DB.list("select * from frid where uid=?",uid);
     }     //这里调用上面方法的话,上面的缓存是没有效果的,除非到另外一个类中调用,何解?
     public Frid getFrid(long uid,long buid)
     {
         List<Frid> frids=getFrids(uid);
         for(Frid frid:frids){
             ........... 
         }
     }
}为什么在同一个类中Spring Cache缓存失效了。

解决方案 »

  1.   

    官方英文文档740页
    Note
    In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual caching at runtime even if the invoked method is ed with @Cacheable - considering using the aspectj mode in this case.