blob: 5f92189c25084f081474914d5f15a43a33556037 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package testing;
import java.util.HashMap;
import java.util.Map;
public abstract aspect AbstractCache<Key,Value> {
public abstract pointcut cachePoint(Key key);
private Map<Object,Object> cache = new HashMap<Object,Object>();
private Integer hitCount = 0;
private Integer missCount = 0;
Value around(Key key) : cachePoint(key){
Value value = get(key);
if(value == null){
value = proceed(key);
put(key,value);
missCount++;
} else {
hitCount++;
}
return value;
}
@SuppressWarnings("unchecked")
private Value get(Key key){
return (Value) cache.get(key);
}
private void put(Key key, Value value) {
cache.put(key, value);
}
public Integer getHitCount() {
return hitCount;
}
public Integer getMissCount() {
return missCount;
}
}
|