aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs1612/pr351592_2/Caching.aj
blob: 7a2764e551f741959ef1a76134586b8fa243e57f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package caching;

import java.util.HashMap;
import java.util.Map;
  
public abstract aspect Caching<K,V> {
	private Map<K,V> cache = new HashMap<K,V>();

	abstract pointcut cached();

	V around(K a): cached() && args(a) {
		if(cache.containsKey(a)){
			System.out.println("Using cached value for: " + a);
			return cache.get(a);
		}
		else {
			V result = proceed(a);
			cache.put(a, result);
			return result;
		}
	}
}