本文整理汇总了Java中org.ehcache.CacheManager.removeCache方法的典型用法代码示例。如果您正苦于以下问题:Java CacheManager.removeCache方法的具体用法?Java CacheManager.removeCache怎么用?Java CacheManager.removeCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.removeCache方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTem
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testTem() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
.build();
cacheManager.init();
Cache<Long, String> preConfigured =
cacheManager.getCache("preConfigured", Long.class, String.class);
Cache<Long, String> myCache = cacheManager.createCache("myCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)));
myCache.put(1L, "da one!");
myCache.putIfAbsent(0L, "ee");
String value = myCache.get(1L);
System.out.println("Value is " + value);
cacheManager.removeCache("preConfigured");
cacheManager.close();
}
示例2: cachemanagerExample
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void cachemanagerExample() {
// tag::cachemanagerExample[]
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() // <1>
.withCache("preConfigured",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))) // <2>
.build(); // <3>
cacheManager.init(); // <4>
Cache<Long, String> preConfigured =
cacheManager.getCache("preConfigured", Long.class, String.class); // <5>
Cache<Long, String> myCache = cacheManager.createCache("myCache", // <6>
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)));
myCache.put(1L, "da one!"); // <7>
String value = myCache.get(1L); // <8>
cacheManager.removeCache("preConfigured"); // <9>
cacheManager.close(); // <10>
// end::cachemanagerExample[]
}
示例3: test_collector
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test(timeout = 6000)
public void test_collector() throws Exception {
final Queue<Object> messages = new ConcurrentLinkedQueue<>();
final List<String> notifs = new ArrayList<>(6);
final CountDownLatch num = new CountDownLatch(5);
CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.offheap(1, MemoryUnit.MB))
.build();
ManagementRegistryService managementRegistry = new DefaultManagementRegistryService(new DefaultManagementRegistryConfiguration()
.setCacheManagerAlias("my-cm-1"));
CollectorService collectorService = new DefaultCollectorService(new CollectorService.Collector() {
@Override
public void onNotification(ContextualNotification notification) {
onEvent(notification);
}
@Override
public void onStatistics(Collection<ContextualStatistics> statistics) {
onEvent(statistics);
}
void onEvent(Object event) {
messages.offer(event);
if (event instanceof ContextualNotification) {
notifs.add(((ContextualNotification) event).getType());
}
num.countDown();
}
});
// ehcache cache manager
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(managementRegistry)
.using(collectorService)
.build(false);
cacheManager.init();
cacheManager.close();
cacheManager.init();
managementRegistry.withCapability("StatisticCollectorCapability")
.call("startStatisticCollector",
new Parameter(1L, long.class.getName()),
new Parameter(TimeUnit.SECONDS, TimeUnit.class.getName()))
.on(Context.create("cacheManagerName", "my-cm-1"))
.build()
.execute()
.getSingleResult();
Cache<String, String> cache = cacheManager.createCache("my-cache", cacheConfiguration);
cache.put("key", "val");
num.await();
cacheManager.removeCache("my-cache");
cacheManager.close();
assertThat(notifs, equalTo(Arrays.asList("CACHE_MANAGER_AVAILABLE", "CACHE_MANAGER_CLOSED", "CACHE_MANAGER_AVAILABLE", "CACHE_ADDED", "CACHE_REMOVED", "CACHE_MANAGER_CLOSED")));
assertThat(messages.size(), equalTo(7));
}
示例4: testChangesToManagerAreReflectedInConfig
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testChangesToManagerAreReflectedInConfig() {
Store.Provider storeProvider = mock(Store.Provider.class);
when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1);
Store store = mock(Store.class);
CacheEventDispatcherFactory cacheEventNotificationListenerServiceProvider = mock(CacheEventDispatcherFactory.class);
when(storeProvider.createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any())).thenReturn(store);
when(store.getConfigurationChangeListeners()).thenReturn(new ArrayList<>());
when(cacheEventNotificationListenerServiceProvider.createCacheEventDispatcher(store)).thenReturn(mock(CacheEventDispatcher.class));
CacheConfiguration<Long, String> cache1Configuration = new BaseCacheConfiguration<>(Long.class, String.class, null, null, null, ResourcePoolsHelper
.createHeapOnlyPools());
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
caches.put("cache1", cache1Configuration);
DefaultConfiguration config = new DefaultConfiguration(caches, null);
CacheManager cacheManager = new EhcacheManager(config, Arrays.asList(storeProvider,
mock(CacheLoaderWriterProvider.class),
mock(WriteBehindProvider.class),
cacheEventNotificationListenerServiceProvider,
mock(CacheEventListenerProvider.class),
mock(LocalPersistenceService.class)
));
cacheManager.init();
try {
final CacheConfiguration<Long, String> cache2Configuration = new BaseCacheConfiguration<>(Long.class, String.class, null, null, null, ResourcePoolsHelper
.createHeapOnlyPools());
final Cache<Long, String> cache = cacheManager.createCache("cache2", cache2Configuration);
final CacheConfiguration<?, ?> cacheConfiguration = cacheManager.getRuntimeConfiguration()
.getCacheConfigurations()
.get("cache2");
assertThat(cacheConfiguration, notNullValue());
final CacheConfiguration<?, ?> runtimeConfiguration = cache.getRuntimeConfiguration();
assertThat(cacheConfiguration == runtimeConfiguration, is(true));
assertThat(cacheManager.getRuntimeConfiguration().getCacheConfigurations().get("cache1")
== cacheManager.getCache("cache1", Long.class, String.class).getRuntimeConfiguration(), is(true));
cacheManager.removeCache("cache1");
assertThat(cacheManager.getRuntimeConfiguration().getCacheConfigurations().containsKey("cache1"), is(false));
} finally {
cacheManager.close();
}
}
示例5: testCachesAddedAtRuntimeGetReInited
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testCachesAddedAtRuntimeGetReInited() {
Store.Provider storeProvider = mock(Store.Provider.class);
when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1);
Store store = mock(Store.class);
CacheEventDispatcherFactory cacheEventNotificationListenerServiceProvider = mock(CacheEventDispatcherFactory.class);
when(storeProvider.createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any())).thenReturn(store);
when(store.getConfigurationChangeListeners()).thenReturn(new ArrayList<>());
when(cacheEventNotificationListenerServiceProvider.createCacheEventDispatcher(store)).thenReturn(mock(CacheEventDispatcher.class));
CacheConfiguration<Long, String> cache1Configuration = new BaseCacheConfiguration<>(Long.class, String.class, null, null, null, ResourcePoolsHelper
.createHeapOnlyPools());
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
caches.put("cache1", cache1Configuration);
DefaultConfiguration config = new DefaultConfiguration(caches, null);
CacheManager cacheManager = new EhcacheManager(config, Arrays.asList(
storeProvider,
mock(CacheLoaderWriterProvider.class),
mock(WriteBehindProvider.class),
cacheEventNotificationListenerServiceProvider,
mock(CacheEventListenerProvider.class),
mock(LocalPersistenceService.class)
));
cacheManager.init();
CacheConfiguration<Long, String> cache2Configuration = new BaseCacheConfiguration<>(Long.class, String.class, null, null, null, ResourcePoolsHelper
.createHeapOnlyPools());
cacheManager.createCache("cache2", cache2Configuration);
cacheManager.removeCache("cache1");
cacheManager.close();
cacheManager.init();
try {
assertThat(cacheManager.getCache("cache1", Long.class, String.class), nullValue());
assertThat(cacheManager.getCache("cache2", Long.class, String.class), notNullValue());
} finally {
cacheManager.close();
}
}