1 17 18 package org.objectweb.jac.aspects.cache; 19 20 import java.util.Hashtable ; 21 import org.apache.log4j.Logger; 22 import org.objectweb.jac.aspects.timestamp.Timestamps; 23 import org.objectweb.jac.util.ObjectArray; 24 25 public class MethodCache extends Hashtable { 26 static final Logger logger = Logger.getLogger("cache"); 27 28 public MethodCache(Timestamps stamps) { 29 this.stamps = stamps; 30 } 31 32 Timestamps stamps; 33 public Entry getEntry(ObjectArray args, int[] ignoredArgs) { 34 Object [] argsArray = args.getArray(); 35 if (ignoredArgs!=null) { 36 for (int i=0; i<ignoredArgs.length; i++) { 37 argsArray[ignoredArgs[i]] = null; 38 } 39 } 40 Entry entry = (Entry)get(args); 41 if (entry!=null) { 42 logger.debug(" cache hit "+args.hashCode()); 43 if (stamps!=null) { 44 int argCount = argsArray.length; 45 long entryTime = entry.time; 46 int i; 47 for (i=0; i<argCount; i++) { 48 Object arg = argsArray[i]; 49 if (arg!=null) { 50 long mtime = stamps.getStamp(arg); 51 if (mtime > entryTime) { 52 logger.debug( 53 " outdated for arg "+i+"("+arg+"): "+ 54 mtime+">"+entryTime); 55 break; 56 } 57 } 58 } 59 if (i==argCount) return (Entry)get(args); 61 else 62 return null; 63 } else { 64 return ((Entry)get(args)); 65 } 66 } else { 67 logger.debug(" cache miss "+args.hashCode()); 68 return null; 69 } 70 } 71 72 public void putEntry(ObjectArray args, Object value) { 73 put(args,new Entry(value)); 74 } 75 76 public static class Entry { 77 long time; 78 public Object value; 79 public Entry(Object value) { 80 this.value = value; 81 this.time = System.currentTimeMillis(); 82 } 83 } 84 } 85 | Popular Tags |