当前位置: 首页>>代码示例>>Java>>正文


Java CacheManagerBuilder.newCacheManager方法代码示例

本文整理汇总了Java中org.ehcache.config.builders.CacheManagerBuilder.newCacheManager方法的典型用法代码示例。如果您正苦于以下问题:Java CacheManagerBuilder.newCacheManager方法的具体用法?Java CacheManagerBuilder.newCacheManager怎么用?Java CacheManagerBuilder.newCacheManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ehcache.config.builders.CacheManagerBuilder的用法示例。


在下文中一共展示了CacheManagerBuilder.newCacheManager方法的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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:EhcacheConfiguration.java

示例2: testSerializers

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的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();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例3: testCopiers

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testCopiers() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/cache-copiers.xml"));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();

  Cache<Description, Person> bar = cacheManager.getCache("bar", Description.class, Person.class);
  Description desc = new Description(1234, "foo");
  Person person = new Person("Bar", 24);
  bar.put(desc, person);
  assertEquals(person, bar.get(desc));
  assertNotSame(person, bar.get(desc));

  Cache<Long, Person> baz = cacheManager.getCache("baz", Long.class, Person.class);
  baz.put(1L, person);
  assertEquals(person, baz.get(1L));
  assertNotSame(person, baz.get(1L));

  Employee empl = new Employee(1234, "foo", 23);
  Cache<Long, Employee> bak = cacheManager.getCache("bak", Long.class, Employee.class);
  bak.put(1L, empl);
  assertSame(empl, bak.get(1L));
  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:IntegrationConfigurationTest.java

示例4: testLoaderWriter

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testLoaderWriter() throws ClassNotFoundException, SAXException, InstantiationException,
    IOException, IllegalAccessException {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/cache-integration.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  assertThat(cache, notNullValue());
  assertThat(cache.get(1), notNullValue());
  final Number key = new Long(42);
  cache.put(key, "Bye y'all!");
  assertThat(TestCacheLoaderWriter.lastWrittenKey, is(key));

  assertThat(configuration.getCacheConfigurations().containsKey("template1"), is(true));
  final Cache<Number, String> templateCache = cacheManager.getCache("template1", Number.class, String.class);
  assertThat(templateCache, notNullValue());
  assertThat(templateCache.get(1), notNullValue());
  final Number key1 = new Long(100);
  templateCache.put(key1, "Bye y'all!");
  assertThat(TestCacheLoaderWriter.lastWrittenKey, is(key1));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:IntegrationConfigurationTest.java

示例5: testCacheEventListener

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testCacheEventListener() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-cacheEventListener.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  cache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.CREATED));
  cache.put(10, "cat");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
  cache.remove(10);
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.REMOVED));
  cache.put(10, "dog");
  resetValues();
  assertThat(configuration.getCacheConfigurations().containsKey("template1"), is(true));
  final Cache<Number, String> templateCache = cacheManager.getCache("template1", Number.class, String.class);
  templateCache.put(10,"cat");
  assertThat(TestCacheEventListener.FIRED_EVENT, nullValue());
  templateCache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:IntegrationConfigurationTest.java

示例6: testCacheEventListenerWithMultipleListener

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testCacheEventListenerWithMultipleListener() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-multipleCacheEventListener.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  resetValues();
  cache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.CREATED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT, is(nullValue()));
  resetValues();
  cache.put(10, "cat");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT.getType(), is(EventType.UPDATED));
  resetValues();
  cache.remove(10);
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.REMOVED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT.getType(), is(EventType.REMOVED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例7: testThreadPools

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的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();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例8: testThreadPoolsUsingDefaultPool

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的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();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例9: ensureCacheManager

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
private org.ehcache.CacheManager ensureCacheManager() throws MalformedURLException {
  if (manager == null) {
    manager = CacheManagerBuilder.newCacheManager(getConfiguration());
    manager.init();

    cacheManagerImplicitlyCreated = true;
  }

  return manager;
}
 
开发者ID:ehcache,项目名称:ehcache-shiro,代码行数:11,代码来源:EhcacheShiroManager.java

示例10: doPreSetup

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Override
protected void doPreSetup() throws Exception {
    final URL url = this.getClass().getResource(EHCACHE_CONFIG);
    final Configuration xmlConfig = new XmlConfiguration(url);

    cacheManager = CacheManagerBuilder.newCacheManager(xmlConfig);
    cacheManager.init();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:EhcacheTestSupport.java

示例11: test_config_loaded

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void test_config_loaded() throws Exception {
  CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(new XmlConfiguration(getClass().getClassLoader().getResource(xml)));
  myCacheManager.init();
  try {
    DefaultManagementRegistryConfiguration registryConfiguration = null;

    for (ServiceCreationConfiguration<?> configuration : myCacheManager.getRuntimeConfiguration().getServiceCreationConfigurations()) {
      if (configuration instanceof DefaultManagementRegistryConfiguration) {
        registryConfiguration = (DefaultManagementRegistryConfiguration) configuration;
        break;
      }
    }

    assertThat(registryConfiguration, is(not(nullValue())));

    // 1st test: CM alia not set, so generated
    if (xml.endsWith("-1.xml")) {
      expectedConfiguration.setCacheManagerAlias(registryConfiguration.getContext().get("cacheManagerName"));
    }

    assertThat(registryConfiguration, equalTo(expectedConfiguration));

  } finally {
    myCacheManager.close();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:28,代码来源:XmlConfigTest.java

示例12: xmlConfigSample

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void xmlConfigSample() throws Exception {
  // tag::xmlConfig[]
  final URL myUrl = getClass().getResource("/configs/docs/getting-started.xml"); // <1>
  XmlConfiguration xmlConfig = new XmlConfiguration(myUrl); // <2>
  CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); // <3>
  myCacheManager.init();  // <4>
  // end::xmlConfig[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:10,代码来源:GettingStarted.java

示例13: testWriteBehind

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testWriteBehind() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SAXException, IOException, InterruptedException {

  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/writebehind-cache.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  assertThat(cache, notNullValue());
  assertThat(cache.get(1), notNullValue());
  final Number key = 42L;
  TestCacheLoaderWriter.latch = new CountDownLatch(1);
  cache.put(key, "Bye y'all!");
  TestCacheLoaderWriter.latch.await(2, TimeUnit.SECONDS);
  assertThat(TestCacheLoaderWriter.lastWrittenKey, is(key));

  assertThat(configuration.getCacheConfigurations().containsKey("template1"), is(true));
  final Cache<Number, String> templateCache = cacheManager.getCache("template1", Number.class, String.class);
  assertThat(templateCache, notNullValue());
  assertThat(templateCache.get(1), notNullValue());
  final Number key1 = 100L;
  TestCacheLoaderWriter.latch = new CountDownLatch(2);
  templateCache.put(42L, "Howdy!");
  templateCache.put(key1, "Bye y'all!");
  TestCacheLoaderWriter.latch.await(2, TimeUnit.SECONDS);
  assertThat(TestCacheLoaderWriter.lastWrittenKey, is(key1));

}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:29,代码来源:IntegrationConfigurationTest.java

示例14: testXACacheWithXMLConfig

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testXACacheWithXMLConfig() throws Exception {
  // tag::testXACacheWithXMLConfig[]
  BitronixTransactionManager transactionManager =
      TransactionManagerServices.getTransactionManager(); // <1>

  URL myUrl = this.getClass().getResource("/docs/configs/xa-getting-started.xml"); // <2>
  Configuration xmlConfig = new XmlConfiguration(myUrl); // <3>
  CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); // <4>
  myCacheManager.init();

  myCacheManager.close();
  transactionManager.shutdown();
  // end::testXACacheWithXMLConfig[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:16,代码来源:XAGettingStarted.java

示例15: testSimpleConfig

import org.ehcache.config.builders.CacheManagerBuilder; //导入方法依赖的package包/类
@Test
public void testSimpleConfig() throws Exception {
  TransactionManagerServices.getConfiguration().setJournal("null").setServerId("XmlConfigTest");
  BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager();

  final URL myUrl = this.getClass().getResource("/configs/simple-xa.xml");
  Configuration xmlConfig = new XmlConfiguration(myUrl);
  CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig);
  myCacheManager.init();

  myCacheManager.close();
  transactionManager.shutdown();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:14,代码来源:XmlConfigTest.java


注:本文中的org.ehcache.config.builders.CacheManagerBuilder.newCacheManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。