You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Caching.aj 420B

12345678910111213141516171819202122
  1. package caching;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. public abstract aspect Caching<K,V> {
  5. private Map<K,V> cache = new HashMap<K,V>();
  6. abstract pointcut cached();
  7. V around(K a): cached() && args(a) {
  8. if(cache.containsKey(a)){
  9. System.out.println("Using cached value for: " + a);
  10. return cache.get(a);
  11. }
  12. else {
  13. V result = proceed(a);
  14. cache.put(a, result);
  15. return result;
  16. }
  17. }
  18. }