1 package net.sf.appstatus.support.spring.cache;
2
3 import java.util.Collection;
4 import java.util.concurrent.ConcurrentHashMap;
5 import java.util.concurrent.ConcurrentMap;
6
7 import org.springframework.cache.Cache;
8 import org.springframework.cache.CacheManager;
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 public class AppStatusCacheManager implements CacheManager {
40 private CacheManager cacheManager;
41
42 private final ConcurrentMap<String, AppStatusCacheAdapter> cacheMap = new ConcurrentHashMap<String, AppStatusCacheAdapter>(
43 16);
44
45 public AppStatusCacheManager() {
46 }
47
48 public Cache getCache(String name) {
49 Cache cache = cacheManager.getCache(name);
50 if(cache == null){
51 return null;
52 }
53 AppStatusCacheAdapter result = cacheMap.get(cache.getName());
54
55 if (result == null) {
56 result = new AppStatusCacheAdapter(cache);
57 cacheMap.put(cache.getName(), result);
58 }
59
60 return result;
61 }
62
63 public Collection<String> getCacheNames() {
64 return cacheManager.getCacheNames();
65 }
66
67 public void setCacheManager(CacheManager cacheManager) {
68 this.cacheManager = cacheManager;
69 }
70 }