abstract aspect Caching {
     interface ToBeCached {

        java.util.Vector getAll();
     }

     int ToBeCached.cachedValue = -1;

     abstract pointcut getValue(ToBeCached t);
     abstract pointcut invalidate(ToBeCached t);

     int around(ToBeCached t): getValue(t) {
         if(t.cachedValue!=-1) {
	    System.out.println(" cached value used ");
            return t.cachedValue;
         }
         t.cachedValue = proceed(t);
         return t.cachedValue;
     }

     before(ToBeCached t):invalidate(t) {
         java.util.Vector all = t.getAll();
 
         t.cachedValue=-1;        
         for(int i=0; i<all.size(); i++) {
            ((ToBeCached)all.elementAt(i)).cachedValue = -1;
         }
     }
}

