@Test public void testAddCacheIfAbsent() { Configuration config = new Configuration().defaultCache(new CacheConfiguration().maxElementsInMemory(100)); CacheManager manager = new CacheManager(config); try { manager.addCache("present"); assertThat(manager.addCacheIfAbsent(new Cache(new CacheConfiguration("present", 1000))), sameInstance(manager.getEhcache("present"))); Ehcache theCache = new Cache(new CacheConfiguration("absent", 1000)); Ehcache cache = manager.addCacheIfAbsent(theCache); assertNotNull(cache); assertThat(cache, sameInstance(theCache)); assertThat(cache.getName(), is("absent")); Ehcache other = new Cache(new CacheConfiguration(cache.getName(), 1000)); Ehcache actual = manager.addCacheIfAbsent(other); assertThat(actual, notNullValue()); assertThat(actual, not(sameInstance(other))); assertThat(actual, sameInstance(cache)); Ehcache newCache = new Cache(new CacheConfiguration(cache.getName(), 1000)); manager.removeCache(actual.getName()); actual = manager.addCacheIfAbsent(newCache); assertThat(actual, notNullValue()); assertThat(actual, not(sameInstance(cache))); assertThat(actual, sameInstance(newCache)); assertThat(manager.addCacheIfAbsent(new Cache(new CacheConfiguration(actual.getName(), 1000))), sameInstance(actual)); assertThat(manager.addCacheIfAbsent((Ehcache) null), nullValue()); } finally { manager.shutdown(); } }
public synchronized Ehcache addCacheIfAbsent(final Ehcache cache) { checkStatus(); return cache == null ? null : addCacheNoCheck(cache, false); }
CacheManager { public synchronized Ehcache addCacheIfAbsent(final Ehcache cache) { checkStatus(); return cache == null ? null : addCacheNoCheck(cache, false); } }
CacheManager { public synchronized Ehcache addCacheIfAbsent(final Ehcache cache) { checkStatus(); return cache == null ? null : addCacheNoCheck(cache, false); } CacheManager(Configuration configuration);  CacheManager(String configurationFileName);  CacheManager(URL configurationURL);  CacheManager(InputStream configurationInputStream);  CacheManager(); }
CacheManager { public synchronized Ehcache addCacheIfAbsent(final Ehcache cache) { checkStatus(); return cache == null ? null : addCacheNoCheck(cache, false); } CacheManager(Configuration configuration);  CacheManager(String configurationFileName);  CacheManager(URL configurationURL);  CacheManager(InputStream configurationInputStream);  CacheManager(); String getClusterUUID(); Store createTerracottaStore(Ehcache cache); WriteBehind createTerracottaWriteBehind(Ehcache cache); CacheEventListener createTerracottaEventReplicator(Ehcache cache); static CacheManager create(); static CacheManager getInstance(); static CacheManager create(String configurationFileName); static CacheManager create(URL configurationFileURL); static CacheManager create(InputStream inputStream); static CacheManager create(Configuration config); Cache getCache(String name); Ehcache getEhcache(String name); synchronized void addCache(String cacheName); void addCache(Cache cache); synchronized void addCache(Ehcache cache); synchronized void addDecoratedCache(Ehcache decoratedCache); synchronized void addDecoratedCacheIfAbsent(Ehcache decoratedCache); boolean cacheExists(String cacheName); void removalAll(); synchronized void removeCache(String cacheName); void shutdown(); String[] getCacheNames(); Status getStatus(); void clearAll(); void clearAllStartingWith(String prefix); CacheManagerPeerProvider getCacheManagerPeerProvider(String scheme); Map<String, CacheManagerPeerProvider> getCacheManagerPeerProviders(); CacheManagerPeerListener getCachePeerListener(String scheme); CacheManagerEventListener getCacheManagerEventListener(); void setCacheManagerEventListener(CacheManagerEventListener cacheManagerEventListener); CacheManagerEventListenerRegistry getCacheManagerEventListenerRegistry(); synchronized void replaceCacheWithDecoratedCache(Ehcache ehcache, Ehcache decoratedCache); String getName(); boolean isNamed(); void setName(String name); @Override String toString(); String getDiskStorePath(); FailSafeTimer getTimer(); CacheCluster getCluster(ClusterScheme scheme); String getOriginalConfigurationText(); String getActiveConfigurationText(); String getOriginalConfigurationText(String cacheName); String getActiveConfigurationText(String cacheName); @Override int hashCode(); synchronized Ehcache addCacheIfAbsent(final Ehcache cache); synchronized Ehcache addCacheIfAbsent(final String cacheName); TransactionController getTransactionController(); }
CacheManager { public synchronized Ehcache addCacheIfAbsent(final Ehcache cache) { checkStatus(); return cache == null ? null : addCacheNoCheck(cache, false); } CacheManager(Configuration configuration);  CacheManager(String configurationFileName);  CacheManager(URL configurationURL);  CacheManager(InputStream configurationInputStream);  CacheManager(); String getClusterUUID(); Store createTerracottaStore(Ehcache cache); WriteBehind createTerracottaWriteBehind(Ehcache cache); CacheEventListener createTerracottaEventReplicator(Ehcache cache); static CacheManager create(); static CacheManager getInstance(); static CacheManager create(String configurationFileName); static CacheManager create(URL configurationFileURL); static CacheManager create(InputStream inputStream); static CacheManager create(Configuration config); Cache getCache(String name); Ehcache getEhcache(String name); synchronized void addCache(String cacheName); void addCache(Cache cache); synchronized void addCache(Ehcache cache); synchronized void addDecoratedCache(Ehcache decoratedCache); synchronized void addDecoratedCacheIfAbsent(Ehcache decoratedCache); boolean cacheExists(String cacheName); void removalAll(); synchronized void removeCache(String cacheName); void shutdown(); String[] getCacheNames(); Status getStatus(); void clearAll(); void clearAllStartingWith(String prefix); CacheManagerPeerProvider getCacheManagerPeerProvider(String scheme); Map<String, CacheManagerPeerProvider> getCacheManagerPeerProviders(); CacheManagerPeerListener getCachePeerListener(String scheme); CacheManagerEventListener getCacheManagerEventListener(); void setCacheManagerEventListener(CacheManagerEventListener cacheManagerEventListener); CacheManagerEventListenerRegistry getCacheManagerEventListenerRegistry(); synchronized void replaceCacheWithDecoratedCache(Ehcache ehcache, Ehcache decoratedCache); String getName(); boolean isNamed(); void setName(String name); @Override String toString(); String getDiskStorePath(); FailSafeTimer getTimer(); CacheCluster getCluster(ClusterScheme scheme); String getOriginalConfigurationText(); String getActiveConfigurationText(); String getOriginalConfigurationText(String cacheName); String getActiveConfigurationText(String cacheName); @Override int hashCode(); synchronized Ehcache addCacheIfAbsent(final Ehcache cache); synchronized Ehcache addCacheIfAbsent(final String cacheName); TransactionController getTransactionController(); static final String DEFAULT_NAME; static final List<CacheManager> ALL_CACHE_MANAGERS; static final String ENABLE_SHUTDOWN_HOOK_PROPERTY; }