@Override
public Cache createCache(String name)
{
if (manager == null)
{
throw new CacheException("CacheFactory was not initialized. Call init() before creating a cache.");
}
try
{
net.sf.ehcache.Cache cache = manager.getCache(name);
if (cache == null)
{
log.warn("Could not find a specific ehcache configuration for cache named [" + name
+ "]; using defaults.");
manager.addCache(name);
cache = manager.getCache(name);
}
Ehcache backingCache = cache;
if (!backingCache.getCacheEventNotificationService().hasCacheEventListeners())
{
if (listeners.size() > 0)
{
for (CacheEventListener listener : listeners)
{
if (!backingCache.getCacheEventNotificationService().getCacheEventListeners()
.contains(listener))
{
backingCache.getCacheEventNotificationService().registerListener(listener);
}
}
}
}
this.cache = new EhCacheWrapper(cache);
return this.cache;
}
catch (net.sf.ehcache.CacheException e)
{
throw new CacheException("Could not create cache: " + name, e);
}
}