本文整理汇总了Java中org.ehcache.config.builders.CacheManagerBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java CacheManagerBuilder.build方法的具体用法?Java CacheManagerBuilder.build怎么用?Java CacheManagerBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.config.builders.CacheManagerBuilder
的用法示例。
在下文中一共展示了CacheManagerBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CacheProvider
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Inject
public CacheProvider(Config config) {
Objects.requireNonNull(config, Required.CONFIG.toString());
if (config.isClusteredCached()) {
CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create(config.getCacheClusterUrl()))
.autoCreate());
this.cacheManager = clusteredCacheManagerBuilder.build(true);
} else {
this.cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build();
this.cacheManager.init();
}
initApplicationCache();
initAuthenticationCache();
initRequestCache();
initServerEventCache();
initWebSocketCache();
}
示例3: testCloseCacheManagerSingleClient
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testCloseCacheManagerSingleClient() {
CacheManagerBuilder<PersistentCacheManager> cacheManagerBuilder = clusteredCacheManagerBuilder
.withCache("test", newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB))));
PersistentCacheManager persistentCacheManager1 = cacheManagerBuilder.build(true);
persistentCacheManager1.close();
persistentCacheManager1.init();
Cache<Long, String> cache = persistentCacheManager1.getCache("test", Long.class, String.class);
cache.put(1L, "One");
assertThat(cache.get(1L), is("One"));
persistentCacheManager1.close();
}
示例4: testClusteredCacheWithLoaderWriter
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testClusteredCacheWithLoaderWriter() {
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
= CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
.autoCreate());
final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
try {
CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB)))
.withLoaderWriter(new TestLoaderWriter())
.build();
cacheManager.createCache("test", config);
fail("IllegalStateException expected");
} catch (IllegalStateException e){
assertThat(e.getCause().getMessage(), is("CacheLoaderWriter is not supported with clustered tiers"));
}
cacheManager.close();
}
示例5: testLargeValues
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testLargeValues() throws Exception {
DefaultStatisticsService statisticsService = new DefaultStatisticsService();
CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
newCacheManagerBuilder()
.using(statisticsService)
.with(cluster(CLUSTER_URI).autoCreate())
.withCache("small-cache", newCacheConfigurationBuilder(Long.class, BigInteger.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(clusteredDedicated("secondary-server-resource", 4, MemoryUnit.MB))));
// The idea here is to add big things in the cache, and cause eviction of them to see if something crashes
try(PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true)) {
Cache<Long, BigInteger> cache = cacheManager.getCache("small-cache", Long.class, BigInteger.class);
Random random = new Random();
for (long i = 0; i < 100; i++) {
BigInteger value = new BigInteger(30 * 1024 * 128 * (1 + random.nextInt(10)), random);
cache.put(i, value);
}
}
}
示例6: testTerminationBeforeCacheRemove
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
@Ignore("Need to decide if we close cache entity in a daemon thread")
public void testTerminationBeforeCacheRemove() throws Exception {
CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
.autoCreate()
.defaultServerResource("primary-server-resource"))
.withCache("simple-cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
cacheManager.init();
cluster.getClusterControl().terminateAllServers();
new TimeLimitedTask<Void>(5, TimeUnit.SECONDS) {
@Override
Void runTask() throws Exception {
// CacheManager.removeCache silently "fails" when a timeout is recognized
cacheManager.removeCache("simple-cache");
return null;
}
}.run();
}
示例7: 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();
}
示例8: startServers
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Before
public void startServers() throws Exception {
CLUSTER.getClusterControl().startAllServers();
CLUSTER.getClusterControl().waitForActive();
CLUSTER.getClusterControl().waitForRunningPassivesInStandby();
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
= CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER.getConnectionURI().resolve("/cm-replication"))
.timeouts(TimeoutsBuilder.timeouts() // we need to give some time for the failover to occur
.read(Duration.ofMinutes(1))
.write(Duration.ofMinutes(1)))
.autoCreate()
.defaultServerResource("primary-server-resource"));
CACHE_MANAGER = clusteredCacheManagerBuilder.build(true);
CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(100, EntryUnit.ENTRIES)
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 4, MemoryUnit.MB)))
.add(ClusteredStoreConfigurationBuilder.withConsistency(cacheConsistency))
.build();
CACHE1 = CACHE_MANAGER.createCache("clustered-cache", config);
CACHE2 = CACHE_MANAGER.createCache("another-cache", config);
}
示例9: testGetExpiredTwoClients
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testGetExpiredTwoClients() {
TestTimeSource timeSource = new TestTimeSource();
TimeSourceConfiguration timeSourceConfiguration = new TimeSourceConfiguration(timeSource);
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
commonClusteredCacheManagerBuilder.using(timeSourceConfiguration);
final PersistentCacheManager cacheManager1 = clusteredCacheManagerBuilder.build(true);
final PersistentCacheManager cacheManager2 = clusteredCacheManagerBuilder.build(true);
final Cache<Long, String> cache1 = cacheManager1.getCache("clustered-cache", Long.class, String.class);
final Cache<Long, String> cache2 = cacheManager2.getCache("clustered-cache", Long.class, String.class);
assertThat(cache2.get(1L), nullValue());
cache1.put(1L, "value1");
assertThat(cache1.get(1L), is("value1"));
timeSource.advanceTime(1L);
assertThat(cache2.get(1L), nullValue());
assertThat(cache1.get(1L), nullValue());
cacheManager2.close();
cacheManager1.close();
}
示例10: testCloseCacheManagerMultipleClients
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testCloseCacheManagerMultipleClients() {
CacheManagerBuilder<PersistentCacheManager> cacheManagerBuilder = clusteredCacheManagerBuilder
.withCache("test", newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB))));
PersistentCacheManager persistentCacheManager1 = cacheManagerBuilder.build(true);
PersistentCacheManager persistentCacheManager2 = cacheManagerBuilder.build(true);
Cache<Long, String> cache = persistentCacheManager1.getCache("test", Long.class, String.class);
cache.put(1L, "One");
assertThat(cache.get(1L), is("One"));
persistentCacheManager1.close();
assertThat(persistentCacheManager1.getStatus(), is(Status.UNINITIALIZED));
Cache<Long, String> cache2 = persistentCacheManager2.getCache("test", Long.class, String.class);
assertThat(cache2.get(1L), is("One"));
persistentCacheManager2.close();
}
示例11: testClusteredCacheWithSerializableValue
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testClusteredCacheWithSerializableValue() throws Exception {
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
newCacheManagerBuilder().with(cluster(CLUSTER_URI).autoCreate())
.withCache("clustered-cache", newCacheConfigurationBuilder(Long.class, Person.class,
newResourcePoolsBuilder().with(clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB))));
PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
Cache<Long, Person> cache = cacheManager.getCache("clustered-cache", Long.class, Person.class);
cache.put(38L, new Person("Clustered Joe", 28));
cacheManager.close();
cacheManager = clusteredCacheManagerBuilder.build(true);
cache = cacheManager.getCache("clustered-cache", Long.class, Person.class);
assertThat(cache.get(38L).name, is("Clustered Joe"));
}
示例12: basicClusteredBulk
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void basicClusteredBulk() throws Exception {
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
newCacheManagerBuilder()
.with(cluster(CLUSTER.getConnectionURI().resolve("/bulk-cm")).autoCreate())
.withCache("clustered-cache", newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB)))
.add(new ClusteredStoreConfiguration(Consistency.STRONG)));
try (PersistentCacheManager cacheManager1 = clusteredCacheManagerBuilder.build(true)) {
try (PersistentCacheManager cacheManager2 = clusteredCacheManagerBuilder.build(true)) {
final Cache<Long, String> cache1 = cacheManager1.getCache("clustered-cache", Long.class, String.class);
final Cache<Long, String> cache2 = cacheManager2.getCache("clustered-cache", Long.class, String.class);
Map<Long, String> entriesMap = new HashMap<>();
entriesMap.put(1L, "one");
entriesMap.put(2L, "two");
entriesMap.put(3L, "three");
cache1.putAll(entriesMap);
Set<Long> keySet = new HashSet<>(Arrays.asList(1L, 2L, 3L));
Map<Long, String> all = cache2.getAll(keySet);
assertThat(all.get(1L), is("one"));
assertThat(all.get(2L), is("two"));
assertThat(all.get(3L), is("three"));
cache2.removeAll(keySet);
all = cache1.getAll(keySet);
assertThat(all.get(1L), nullValue());
assertThat(all.get(2L), nullValue());
assertThat(all.get(3L), nullValue());
}
}
}
示例13: basicCacheCRUD
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void basicCacheCRUD() throws Exception {
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
= CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER.getConnectionURI().resolve("/crud-cm"))
.autoCreate()
.defaultServerResource("primary-server-resource"));
final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
cacheManager.init();
try {
CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 1, MemoryUnit.MB))).build();
Cache<Long, String> cache = cacheManager.createCache("clustered-cache", config);
cache.put(1L, "The one");
assertThat(cache.containsKey(2L), is(false));
cache.put(2L, "The two");
assertThat(cache.containsKey(2L), is(true));
cache.put(1L, "Another one");
cache.put(3L, "The three");
assertThat(cache.get(1L), equalTo("Another one"));
assertThat(cache.get(2L), equalTo("The two"));
assertThat(cache.get(3L), equalTo("The three"));
cache.remove(1L);
assertThat(cache.get(1L), is(nullValue()));
cache.clear();
assertThat(cache.get(1L), is(nullValue()));
assertThat(cache.get(2L), is(nullValue()));
assertThat(cache.get(3L), is(nullValue()));
} finally {
cacheManager.close();
}
}
示例14: testContainsKeyExpiredTwoClients
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testContainsKeyExpiredTwoClients() {
TestTimeSource timeSource = new TestTimeSource();
TimeSourceConfiguration timeSourceConfiguration = new TimeSourceConfiguration(timeSource);
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
commonClusteredCacheManagerBuilder.using(timeSourceConfiguration);
final PersistentCacheManager cacheManager1 = clusteredCacheManagerBuilder.build(true);
final PersistentCacheManager cacheManager2 = clusteredCacheManagerBuilder.build(true);
final Cache<Long, String> cache1 = cacheManager1.getCache("clustered-cache", Long.class, String.class);
final Cache<Long, String> cache2 = cacheManager2.getCache("clustered-cache", Long.class, String.class);
assertThat(cache2.get(1L), nullValue());
cache1.put(1L, "value1");
assertThat(cache1.containsKey(1L), is(true));
timeSource.advanceTime(1L);
assertThat(cache1.containsKey(1L), is(false));
assertThat(cache2.containsKey(1L), is(false));
cacheManager2.close();
cacheManager1.close();
}
示例15: testTerminationThenContainsKey
import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testTerminationThenContainsKey() throws Exception {
CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
.timeouts(TimeoutsBuilder.timeouts().read(Duration.of(1, ChronoUnit.SECONDS)).build())
.autoCreate()
.defaultServerResource("primary-server-resource"))
.withCache("simple-cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
cacheManager.init();
final Cache<Long, String> cache = cacheManager.getCache("simple-cache", Long.class, String.class);
cache.put(1L, "un");
cache.put(2L, "deux");
cache.put(3L, "trois");
assertThat(cache.containsKey(2L)).isTrue();
cluster.getClusterControl().terminateAllServers();
boolean value = new TimeLimitedTask<Boolean>(5, TimeUnit.SECONDS) {
@Override
Boolean runTask() throws Exception {
return cache.containsKey(2L);
}
}.run();
assertThat(value).isFalse();
}