public static void clear() { while (!mutex.compareAndSet(false, true)) ; try { for (AbstractCache<?, ?> cache : cacheList.values()) { cache.clear(); } } finally { mutex.compareAndSet(true, false); } }
/** * Gets a value from the named cache with the given key * * @param <K> * @param <V> * @param cacheName * @param key * @return * @throws CacheException */ public static <K, V> V getFromCache(String cacheName, K key) throws CacheException { AbstractCache<K, V> cache; V value = null; try { cache = getCache(cacheName); value = cache != null ? cache.get(key) : null; } catch (CacheException e) { throw e; } return value; }
/** * This method is already invoked from within a critical section. Do not synchronize any further * * @param cacheClass * @return */ private static AbstractCache<?, ?> createCache(String name) throws CacheException { Map<String, String> map = config.remove(name); if (map != null) { AbstractCache<?, ?> cache; try { cache = CacheBuilder.build(map, name); } catch (InstantiationException e) { throw new CacheException(e); } cache.init(); return cache; } else { throw new CacheException("Cache [" + name + "] not found"); } }