本文整理汇总了Java中org.ehcache.CacheManager.createCache方法的典型用法代码示例。如果您正苦于以下问题:Java CacheManager.createCache方法的具体用法?Java CacheManager.createCache怎么用?Java CacheManager.createCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.createCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testNoDefaultThreadPoolFails
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testNoDefaultThreadPoolFails() throws Exception {
PooledExecutionServiceConfiguration executionServiceConfiguration = new PooledExecutionServiceConfiguration();
executionServiceConfiguration.addPool("foo", 2, 4);
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(executionServiceConfiguration)
.build(true);
try {
cacheManager.createCache("testCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(10))
.build());
fail("expected IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
cacheManager.close();
}
示例3: testOverSizedObjectPutFailsWithOnHeapAsAuthority
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testOverSizedObjectPutFailsWithOnHeapAsAuthority() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withDefaultSizeOfMaxObjectSize(500, MemoryUnit.B).build(true);
CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, String.class,
newResourcePoolsBuilder()
.heap(100, MemoryUnit.KB).build())
.build();
Cache<String, String> cache = cacheManager.createCache("cache",
cacheConfiguration);
cache.put("key1", getOverSizedObject());
assertThat(cache.get("key1"), nullValue());
cache.put("key1", "value1");
cache.replace("key1", getOverSizedObject());
assertThat(cache.get("key1"), nullValue());
}
示例4: testSerializers
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testSerializers() throws Exception {
Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/default-serializer.xml"));
final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
cacheManager.init();
Cache<Long, Double> bar = cacheManager.getCache("bar", Long.class, Double.class);
bar.put(1L, 1.0);
assertThat(bar.get(1L), equalTo(1.0));
Cache<String, String> baz = cacheManager.getCache("baz", String.class, String.class);
baz.put("1", "one");
assertThat(baz.get("1"), equalTo("one"));
Cache<String, Object> bam = cacheManager.createCache("bam", newCacheConfigurationBuilder(String.class, Object.class, heap(10)).build());
bam.put("1", "one");
assertThat(bam.get("1"), equalTo((Object)"one"));
cacheManager.close();
}
示例5: testThreadPools
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testThreadPools() throws Exception {
Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/thread-pools.xml"));
final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
cacheManager.init();
try {
Cache<String, String> cache = cacheManager.createCache("testThreadPools", newCacheConfigurationBuilder(String.class, String.class, heap(10))
.add(new DefaultCacheLoaderWriterConfiguration(ThreadRememberingLoaderWriter.class))
.add(newUnBatchedWriteBehindConfiguration().useThreadPool("small"))
.build());
cache.put("foo", "bar");
ThreadRememberingLoaderWriter.USED.acquireUninterruptibly();
assertThat(ThreadRememberingLoaderWriter.LAST_SEEN_THREAD.getName(), containsString("[small]"));
} finally {
cacheManager.close();
}
}
示例6: testThreadPoolsUsingDefaultPool
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testThreadPoolsUsingDefaultPool() throws Exception {
Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/thread-pools.xml"));
final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
cacheManager.init();
try {
Cache<String, String> cache = cacheManager.createCache("testThreadPools", newCacheConfigurationBuilder(String.class, String.class, heap(10))
.add(new DefaultCacheLoaderWriterConfiguration(ThreadRememberingLoaderWriter.class))
.add(newUnBatchedWriteBehindConfiguration())
.build());
cache.put("foo", "bar");
ThreadRememberingLoaderWriter.USED.acquireUninterruptibly();
assertThat(ThreadRememberingLoaderWriter.LAST_SEEN_THREAD.getName(), containsString("[big]"));
} finally {
cacheManager.close();
}
}
示例7: 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[]
}
示例8: testStoreByValue
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testStoreByValue() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(false);
cacheManager.init();
DefaultCopierConfiguration<String> copierConfiguration = new DefaultCopierConfiguration<>(
SerializingCopier.<String>asCopierClass(), DefaultCopierConfiguration.Type.VALUE);
final Cache<Long, String> cache1 = cacheManager.createCache("cache1",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(1))
.build());
performAssertions(cache1, true);
final Cache<Long, String> cache2 = cacheManager.createCache("cache2",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(1))
.add(copierConfiguration)
.build());
performAssertions(cache2, false);
final Cache<Long, String> cache3 = cacheManager.createCache("cache3",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(1))
.build());
performAssertions(cache3, true);
cacheManager.close();
}
示例9: main
import org.ehcache.CacheManager; //导入方法依赖的package包/类
public static void main(String[] args){
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured",
CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, String.class))
.build(true);
Cache<Long, String> preConfigured
= cacheManager.getCache("preConfigured", Long.class, String.class);
Cache<Long, TestData> myCache = cacheManager.createCache("myCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, TestData.class));
Cache<Long, TestData2> myCache2 = cacheManager.createCache("myCache2",
CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, TestData2.class));
TestData data=new TestData();
myCache.put(1L, data);
myCache.put(1L, data);
myCache.put(1L,new TestData());
myCache.put(1L, data);
myCache2.put(2l,data.testData2);
data.a=30;
data.testData2.a=50;
TestData value = myCache.get(1L);
System.out.println(value);
cacheManager.close();
}
示例10: testNoDefaultThreadPoolSucceedsWithExplicitConfig
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testNoDefaultThreadPoolSucceedsWithExplicitConfig() throws Exception {
PooledExecutionServiceConfiguration executionServiceConfiguration = new PooledExecutionServiceConfiguration();
executionServiceConfiguration.addPool("foo", 2, 4);
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(new CacheEventDispatcherFactoryConfiguration("foo"))
.using(executionServiceConfiguration)
.build(true);
cacheManager.createCache("testCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(10))
.build());
cacheManager.close();
}
示例11: testDefaultThreadPoolSucceedsWithoutConfig
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testDefaultThreadPoolSucceedsWithoutConfig() throws Exception {
PooledExecutionServiceConfiguration executionServiceConfiguration = new PooledExecutionServiceConfiguration();
executionServiceConfiguration.addDefaultPool("dflt", 2, 4);
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(executionServiceConfiguration)
.build(true);
cacheManager.createCache("testCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(10))
.build());
cacheManager.close();
}
示例12: testCloseWhenRuntimeCacheCreationFails
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testCloseWhenRuntimeCacheCreationFails() throws Exception {
Store.Provider storeProvider = mock(Store.Provider.class);
when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1);
doThrow(new Error("Test EhcacheManager close.")).when(storeProvider).createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any());
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
DefaultConfiguration config = new DefaultConfiguration(caches, null);
final CacheManager cacheManager = new EhcacheManager(config, Arrays.asList(
storeProvider,
mock(CacheLoaderWriterProvider.class),
mock(WriteBehindProvider.class),
mock(CacheEventDispatcherFactory.class),
mock(CacheEventListenerProvider.class),
mock(LocalPersistenceService.class)
));
cacheManager.init();
CacheConfiguration<Long, String> cacheConfiguration = new BaseCacheConfiguration<>(Long.class, String.class, null, null, null, ResourcePoolsHelper
.createHeapOnlyPools());
try {
cacheManager.createCache("cache", cacheConfiguration);
fail();
} catch (Error err) {
assertThat(err.getMessage(), equalTo("Test EhcacheManager close."));
}
cacheManager.close();
assertThat(cacheManager.getStatus(), is(Status.UNINITIALIZED));
}
示例13: testOverSizedObjectGetsReturnedFromLowerTier
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testOverSizedObjectGetsReturnedFromLowerTier() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withDefaultSizeOfMaxObjectSize(500, MemoryUnit.B)
.withDefaultSizeOfMaxObjectGraph(1000)
.build(true);
CacheConfiguration<String, String> objectSize = CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, String.class,
newResourcePoolsBuilder()
.heap(100, MemoryUnit.KB).offheap(10, MemoryUnit.MB).build())
.build();
Cache<String, String> objectSizeCache = cacheManager.createCache("objectSize",
objectSize);
objectSizeCache.put("key1", getOverSizedObject());
assertThat(objectSizeCache.get("key1"), equalTo(getOverSizedObject()));
CacheConfiguration<String, ObjectSizeGreaterThanN> objectGraphSize = CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, ObjectSizeGreaterThanN.class,
newResourcePoolsBuilder()
.heap(100, MemoryUnit.KB).offheap(100, MemoryUnit.MB).build())
.build();
Cache<String, ObjectSizeGreaterThanN> objectGraphSizeCache = cacheManager.createCache("objectGraphSize",
objectGraphSize);
objectGraphSizeCache.put("key1", getObjectSizeGreaterThanN(1002));
assertThat(objectGraphSizeCache.get("key1"), equalTo(getObjectSizeGreaterThanN(1002)));
}
示例14: testNonXA
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testNonXA() throws Exception {
/*
* Ensure the XA provider classes are loadable through the ServiceLoader mechanism.
*/
Set<Class<?>> targetProviders = new HashSet<>();
targetProviders.add(XAStore.Provider.class);
targetProviders.add(TransactionManagerProvider.class);
for (ServiceFactory factory : ClassLoading.libraryServiceLoaderFor(ServiceFactory.class)) {
if (targetProviders.remove(factory.getServiceType())) {
if (targetProviders.isEmpty()) {
break;
}
}
}
assertThat(targetProviders, is(Matchers.empty()));
CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class,
String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.offheap(1, MemoryUnit.MB)
.build())
.build();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
cacheManager.createCache("cache-1", cacheConfiguration);
cacheManager.createCache("cache-2", cacheConfiguration);
cacheManager.close();
}
示例15: testAddingCacheLoaderWriterConfigurationAtCacheLevel
import org.ehcache.CacheManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testAddingCacheLoaderWriterConfigurationAtCacheLevel() {
CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (MyLoader.class);
CacheManager cacheManager = cacheManagerBuilder.build(true);
final Cache<Long, String> cache = cacheManager.createCache("cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100))
.add(new DefaultCacheLoaderWriterConfiguration(klazz))
.build());
Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration()
.getServiceConfigurations();
assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(DefaultCacheLoaderWriterConfiguration.class)));
cacheManager.close();
}