本文整理汇总了Java中org.ehcache.config.builders.CacheManagerBuilder.newCacheManagerBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java CacheManagerBuilder.newCacheManagerBuilder方法的具体用法?Java CacheManagerBuilder.newCacheManagerBuilder怎么用?Java CacheManagerBuilder.newCacheManagerBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.config.builders.CacheManagerBuilder
的用法示例。
在下文中一共展示了CacheManagerBuilder.newCacheManagerBuilder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCacheManager
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
CacheManager createCacheManager() throws IOException {
CacheManager manager;
if (cacheManager != null) {
manager = cacheManager;
} else if (configUri != null) {
manager = CacheManagerBuilder.newCacheManager(new XmlConfiguration(getConfigUriAsUrl()));
} else {
CacheManagerBuilder builder = CacheManagerBuilder.newCacheManagerBuilder();
if (configuration != null) {
builder.withCache(cacheName, configuration);
}
manager = builder.build();
}
return manager;
}
示例2: testPutAll_without_cache_writer
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testPutAll_without_cache_writer() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
HashMap<String, String> stringStringHashMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
stringStringHashMap.put("key" + i, "value" + i);
}
// the call to putAll
myCache.putAll(stringStringHashMap);
for (int i = 0; i < 3; i++) {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
示例3: testAddingWriteBehindConfigurationAtCacheLevel
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testAddingWriteBehindConfigurationAtCacheLevel() {
CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
WriteBehindConfiguration writeBehindConfiguration = WriteBehindConfigurationBuilder.newBatchedWriteBehindConfiguration(Long.MAX_VALUE, SECONDS, 1)
.concurrencyLevel(3)
.queueSize(10)
.build();
Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (SampleLoaderWriter.class);
CacheManager cacheManager = cacheManagerBuilder.build(true);
final Cache<Long, String> cache = cacheManager.createCache("cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100))
.add(writeBehindConfiguration)
.add(new DefaultCacheLoaderWriterConfiguration(klazz))
.build());
Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration()
.getServiceConfigurations();
assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(WriteBehindConfiguration.class)));
cacheManager.close();
}
示例4: testGetAll_without_cache_loader
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testGetAll_without_cache_loader() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to getAll
Map<String, String> fewEntries = myCache.getAll(fewKeysSet);
assertThat(fewEntries.size(), is(2));
assertThat(fewEntries.get("key0"), is("value0"));
assertThat(fewEntries.get("key2"), is("value2"));
}
示例5: testRemoveAll_without_cache_writer
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testRemoveAll_without_cache_writer() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to removeAll
myCache.removeAll(fewKeysSet);
for (int i = 0; i < 3; i++) {
if (i == 0 || i == 2) {
assertThat(myCache.get("key" + i), is(nullValue()));
} else {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
}
示例6: testAddingCacheLoaderWriterConfigurationAtCacheLevel
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的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();
}
示例7: testAddingCacheEventListenerConfigurationAtCacheLevel
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testAddingCacheEventListenerConfigurationAtCacheLevel() {
CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheEventListenerConfiguration cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
.newEventListenerConfiguration(ListenerObject.class, EventType.CREATED).unordered().asynchronous().build();
CacheManager cacheManager = cacheManagerBuilder.build(true);
final Cache<Long, String> cache = cacheManager.createCache("cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100))
.add(cacheEventListenerConfiguration)
.build());
Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration()
.getServiceConfigurations();
assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(DefaultCacheEventListenerConfiguration.class)));
cacheManager.close();
}
示例8: setUp
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
CacheManagerBuilder<CacheManager> builder = CacheManagerBuilder.newCacheManagerBuilder();
cacheManager = builder.build(true);
}