checkIfNotNull(cacheName, "cacheName must not be null");
checkIfNotNull(configuration, "configuration must not be null");
final CacheConfig<K, V> newCacheConfig = createCacheConfig(cacheName, configuration);
if (caches.containsKey(newCacheConfig.getNameWithPrefix())) {
throw new CacheException("A cache named " + cacheName + " already exists.");
}
//create proxy object
final ICache<K, V> cacheProxy = createCacheProxy(newCacheConfig);
//CREATE THE CONFIG ON PARTITION
CacheConfig<K, V> current = createConfigOnPartition(newCacheConfig);
if (current == null) {
//single thread region because createConfigOnPartition is single threaded by partition thread
//UPDATE LOCAL MEMBER
addCacheConfigIfAbsentToLocal(newCacheConfig);
//no need to a putIfAbsent as this is a single threaded region
caches.put(newCacheConfig.getNameWithPrefix(), cacheProxy);
//REGISTER LISTENERS
registerListeners(newCacheConfig, cacheProxy);
return cacheProxy;
}
ICache<?, ?> cache = getOrPutIfAbsent(current.getNameWithPrefix(), cacheProxy);
CacheConfig config = cache.getConfiguration(CacheConfig.class);
if (config.equals(newCacheConfig)) {
return (ICache<K, V>) cache;
}
throw new CacheException("A cache named " + cacheName + " already exists.");
}