class CacheBase implements ApplicationContextAware, InitializingBean {

    protected void addCache(final Cache cache) {
        if (cache == null) {
            getLogger().warn("One of the cache is null");
            return;
        }

        if (caches.put(cache.getName(), cache) != null) {
            String errorMsg = "There are two or more caches with the same name '" + cache.getName() + "'";
            getLogger().error(errorMsg);
            throw new IllegalStateException(errorMsg);
        }

        for (String alias : cache.getAliases()) {
            if (caches.containsKey(alias)) {
                String errorMsg = String.format("The cache with name '%s' uses alias '%s' already defined by cache with name '%s'",
                        cache.getName(), alias, caches.get(alias).getName());
                getLogger().error(errorMsg);
                throw new IllegalStateException(errorMsg);
            } else {
                caches.put(alias, cache);
            }
        }
    }

}