1 18 package org.apache.beehive.netui.util.internal.cache; 19 20 import java.util.Map ; 21 import org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap; 22 23 24 27 public final class ClassLevelCache { 28 29 private static InternalConcurrentHashMap _classCaches = new InternalConcurrentHashMap(); 30 private InternalConcurrentHashMap _caches = new InternalConcurrentHashMap(); 31 32 33 public static ClassLevelCache getCache(Class c) { 34 String className = c.getName(); 35 ClassLevelCache cache = (ClassLevelCache)_classCaches.get(className); 36 37 if(cache == null) { 38 cache = new ClassLevelCache(); 39 _classCaches.put(className, cache); 40 } 41 42 return cache; 43 } 44 45 protected ClassLevelCache() { 46 } 47 48 public Object get(String majorKey, String minorKey) { 49 InternalConcurrentHashMap cache = (InternalConcurrentHashMap)_caches.get(majorKey); 50 return cache != null ? cache.get(minorKey) : null; 51 } 52 53 public Object getCacheObject(String cacheID) { 54 return _caches.get(cacheID); 55 } 56 57 public void setCacheObject(String cacheID, Object object) { 58 _caches.put(cacheID, object); 59 } 60 61 public Map getCacheMap(String cacheID) { 62 return getCacheMap(cacheID, true); 63 } 64 65 public Map getCacheMap(String cacheID, boolean createIfMissing) { 66 InternalConcurrentHashMap cache = (InternalConcurrentHashMap)_caches.get(cacheID); 67 68 if(cache == null && createIfMissing) { 69 cache = new InternalConcurrentHashMap(); 70 _caches.put(cacheID, cache); 71 } 72 73 return cache; 74 } 75 76 public void put(String cacheID, String minorKey, Object value) { 77 assert value != null; 82 getCacheMap(cacheID).put(minorKey, value); 83 } 84 85 public static void clearAll() { 86 _classCaches.clear(); 87 } 88 } 89 | Popular Tags |