org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager Maven / Gradle / Ivy
package org.infinispan.spring.embedded.provider;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.infinispan.Cache;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.spring.common.provider.SpringCache;
import org.springframework.cache.CacheManager;
import org.springframework.util.Assert;
/**
*
* A {@link CacheManager CacheManager
} implementation that is
* backed by an {@link EmbeddedCacheManager
* Infinispan EmbeddedCacheManager
} instance.
*
*
* Note that this CacheManager
does support adding new
* {@link org.infinispan.Cache Caches
} at runtime, i.e. Caches
added
* programmatically to the backing EmbeddedCacheManager
after this
* CacheManager
has been constructed will be seen by this CacheManager
.
*
*
* @author Olaf Bergner
* @author Marius Bogoevici
*
*/
public class SpringEmbeddedCacheManager implements CacheManager {
private final EmbeddedCacheManager nativeCacheManager;
private final ConcurrentMap springCaches = new ConcurrentHashMap<>();
private boolean reactive;
/**
* @param nativeCacheManager Underlying cache manager
*/
public SpringEmbeddedCacheManager(final EmbeddedCacheManager nativeCacheManager) {
this(nativeCacheManager, false);
}
/**
* @param nativeCacheManager Underlying cache manager
*/
public SpringEmbeddedCacheManager(final EmbeddedCacheManager nativeCacheManager, boolean reactive) {
Assert.notNull(nativeCacheManager,
"A non-null instance of EmbeddedCacheManager needs to be supplied");
this.nativeCacheManager = nativeCacheManager;
this.reactive = reactive;
}
@Override
public SpringCache getCache(final String name) {
return springCaches.computeIfAbsent(name, n -> {
final Cache