/** * This method will check if a cache already exists for given cache type and store * if it is not present in the map */ public <K, V> Cache<K, V> createCache(CacheType cacheType, String cacheClassName) throws Exception { //check if lru cache is null, if null create one //check if cache is null for given cache type, if null create one if (!dictionaryCacheAlreadyExists(cacheType)) { synchronized (lock) { if (!dictionaryCacheAlreadyExists(cacheType)) { if (null == carbonLRUCache) { createLRULevelCacheInstance(); } Class<?> clazz = Class.forName(cacheClassName); Constructor<?> constructor = clazz.getConstructors()[0]; constructor.setAccessible(true); Cache cacheObject = (Cache) constructor.newInstance(carbonLRUCache); cacheTypeToCacheMap.put(cacheType, cacheObject); } } } return cacheTypeToCacheMap.get(cacheType); }
/** * This method will check if a cache already exists for given cache type and create in case * it is not present in the map * * @param cacheType type of cache * @param <K> * @param <V> * @return */ public <K, V> Cache<K, V> createCache(CacheType cacheType) { //check if lru cache is null, if null create one //check if cache is null for given cache type, if null create one if (!dictionaryCacheAlreadyExists(cacheType)) { synchronized (lock) { if (!dictionaryCacheAlreadyExists(cacheType)) { if (null == carbonLRUCache) { createLRULevelCacheInstance(); } createDictionaryCacheForGivenType(cacheType); } } } return cacheTypeToCacheMap.get(cacheType); }