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

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

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