1 package com.atlassian.seraph.util;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.Map;
6
7
8
9
10 public class CachedPathMapper extends PathMapper
11 {
12 private Map cacheMap;
13 private Map cacheAllMap;
14
15
16
17
18
19
20
21
22 public CachedPathMapper(Map cacheMap, Map cacheAllMap)
23 {
24
25 this.cacheMap = Collections.synchronizedMap(cacheMap);
26 this.cacheAllMap = Collections.synchronizedMap(cacheAllMap);
27 }
28
29 public String get(String path)
30 {
31
32 String result = (String) cacheMap.get(path);
33 if (result != null)
34 {
35
36 return result;
37 }
38
39 result = super.get(path);
40
41 cacheMap.put(path, result);
42 return result;
43 }
44
45 public Collection getAll(String path)
46 {
47 Collection result = (Collection) cacheAllMap.get(path);
48
49 if (result != null)
50 {
51
52 return result;
53 }
54
55 result = super.getAll(path);
56
57 cacheAllMap.put(path, result);
58 return result;
59 }
60
61 public void put(String key, String pattern)
62 {
63 cacheMap.remove(key);
64 cacheAllMap.remove(key);
65
66 super.put(key, pattern);
67 }
68 }