本文整理汇总了Java中org.ehcache.config.builders.CacheManagerBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CacheManagerBuilder类的具体用法?Java CacheManagerBuilder怎么用?Java CacheManagerBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheManagerBuilder类属于org.ehcache.config.builders包,在下文中一共展示了CacheManagerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTem
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的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: load
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
public void load(String vocabFile, float cacheSize) throws IOException {
int size = (int) (cacheSize * createVirtualMem(vocabFile, cacheSize));
this.mCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured", CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, double[].class, ResourcePoolsBuilder.heap(size))
.build())
.build(true);
this.mCache = mCacheManager.getCache("preConfigured", String.class, double[].class);
this.UNK = mWEVirtualMemory.swap(mCache, size);
if (this.UNK == null)
throw new IOException("Vector <UNK> not found!");
}
示例3: ServerInterfaceCache
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
private ServerInterfaceCache() {
this.cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("airports",
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.offheap(10, MemoryUnit.MB))
)
.build(true);
this.airportCache = this.cacheManager.getCache("airports", String.class, String.class);
this.airplaneCache = this.cacheManager.createCache("airplanes",
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.offheap(10, MemoryUnit.MB)).build());
this.flightCache = this.cacheManager.createCache("flights",
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.offheap(10, MemoryUnit.MB)).build());
}
示例4: 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;
}
示例5: EhCacheDao
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
/**
* To initiate EhCacheDao with cacheManager and cache.
*
* @param cacheName
* name of the cache.
* @param cacheSize
* cache size.
*/
public EhCacheDao(final String cacheName, final long cacheSize) {
setCacheManager(CacheManagerBuilder.newCacheManagerBuilder()
.using(PooledExecutionServiceConfigurationBuilder.newPooledExecutionServiceConfigurationBuilder()
.defaultPool("dflt", 0, 10)
.pool("defaultEventPool", 1, 3)
.pool("cache2Pool", 2, 2)
.build())
.withDefaultEventListenersThreadPool("defaultEventPool")
.withCache(cacheName, CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, byte[].class, ResourcePoolsBuilder.heap(cacheSize))
.build())
.build(true));
setCache(cacheManager.getCache(cacheName, Long.class, byte[].class));
}
示例6: 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();
}
示例7: 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();
}
示例8: cachemanagerExample
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的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[]
}
示例9: testCacheEventListener
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
@Test
public void testCacheEventListener() {
// tag::cacheEventListener[]
CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
.newEventListenerConfiguration(new ListenerObject(), EventType.CREATED, EventType.UPDATED) // <1>
.unordered().asynchronous(); // <2>
final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("foo",
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
.add(cacheEventListenerConfiguration) // <3>
).build(true);
final Cache<String, String> cache = manager.getCache("foo", String.class, String.class);
cache.put("Hello", "World"); // <4>
cache.put("Hello", "Everyone"); // <5>
cache.remove("Hello"); // <6>
// end::cacheEventListener[]
manager.close();
}
示例10: testClusteredCacheWithXA
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
@Test
public void testClusteredCacheWithXA() throws Exception {
TransactionManagerServices.getConfiguration().setJournal("null");
BitronixTransactionManager transactionManager =
TransactionManagerServices.getTransactionManager();
PersistentCacheManager persistentCacheManager = null;
try {
CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class))
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")).autoCreate())
.withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB))
)
.add(new XAStoreConfiguration("xaCache"))
.build()
)
.build(true);
} catch (StateTransitionException e) {
assertThat(e.getCause().getCause().getMessage(), is("Unsupported resource type : interface org.ehcache.clustered.client.config.DedicatedClusteredResourcePool"));
}
transactionManager.shutdown();
}
示例11: testCanGetCapabilities
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
@Test
public void testCanGetCapabilities() {
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(10))
.build();
ManagementRegistryService managementRegistry = new DefaultManagementRegistryService(new DefaultManagementRegistryConfiguration().setCacheManagerAlias("myCM"));
CacheManager cacheManager1 = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("aCache", cacheConfiguration)
.using(managementRegistry)
.build(true);
assertThat(managementRegistry.getCapabilities()).hasSize(4);
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(0).getName()).isEqualTo("ActionsCapability");
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(1).getName()).isEqualTo("SettingsCapability");
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(2).getName()).isEqualTo("StatisticCollectorCapability");
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(3).getName()).isEqualTo("StatisticsCapability");
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(0).getDescriptors()).hasSize(4);
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(3).getDescriptors()).hasSize(ONHEAP_DESCRIPTORS.size() + CACHE_DESCRIPTORS.size());
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(0).getCapabilityContext().getAttributes()).hasSize(2);
assertThat(new ArrayList<Capability>(managementRegistry.getCapabilities()).get(3).getCapabilityContext().getAttributes()).hasSize(2);
cacheManager1.close();
}
示例12: eventsTest
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
public void eventsTest() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(PooledExecutionServiceConfigurationBuilder.newPooledExecutionServiceConfigurationBuilder()
.pool("defaultEventPool", 1, 3).pool("cache2Pool", 2, 2).build())
.withDefaultEventListenersThreadPool(
"defaultEventPool")
.withCache("cache1",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES))
.add(CacheEventListenerConfigurationBuilder.newEventListenerConfiguration(
new ListenerObject(), EventType.CREATED, EventType.UPDATED)))
.withCache("cache2", CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES))
.add(CacheEventListenerConfigurationBuilder.newEventListenerConfiguration(new ListenerObject(),
EventType.CREATED, EventType.UPDATED))
.withEventListenersThreadPool("cache2Pool"))
.build(true);
Cache<Long, String> cache1 = cacheManager.getCache("cache1", Long.class, String.class);
Cache<Long, String> cache2 = cacheManager.getCache("cache2", Long.class, String.class);
cacheManager.close();
}
示例13: setUp
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
UnitTestConnectionService.add(CLUSTER_URI,
new UnitTestConnectionService.PassthroughServerBuilder()
.resource("primary-server-resource", 8, MemoryUnit.MB)
.resource("secondary-server-resource", 8, MemoryUnit.MB)
.build());
cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER_URI).autoCreate()
.defaultServerResource("primary-server-resource")
.resourcePool("resource-pool-a", 2, MemoryUnit.MB, "secondary-server-resource")
.resourcePool("resource-pool-b", 4, MemoryUnit.MB))
.withCache("dedicated-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 4, MemoryUnit.MB))))
.withCache("shared-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool-a"))))
.build();
cacheManager.init();
dedicatedCache = cacheManager.getCache("dedicated-cache", Long.class, String.class);
sharedCache = cacheManager.getCache("shared-cache", Long.class, String.class);
}
示例14: 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();
}
示例15: testNoDefaultThreadPoolFails
import org.ehcache.config.builders.CacheManagerBuilder; //导入依赖的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();
}