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


Java CacheManager.init方法代码示例

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


在下文中一共展示了CacheManager.init方法的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();
}
 
开发者ID:compasses,项目名称:elastic-rabbitmq,代码行数:24,代码来源:TestEhcache.java

示例2: 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();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例3: testCopiers

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

示例8: 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();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例9: 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[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:GettingStarted.java

示例10: 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();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:26,代码来源:OnHeapStoreByValueTest.java

示例11: FieldCache

import org.ehcache.CacheManager; //导入方法依赖的package包/类
public FieldCache(){
    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("fields",
                    CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(DEFAULT_CACHE_SIZE_ENTRIES)))
            .build();
    cacheManager.init();
    fieldCache = cacheManager.getCache("fields", String.class, String.class);
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:9,代码来源:FieldCache.java

示例12: test_config_loaded

import org.ehcache.CacheManager; //导入方法依赖的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

示例13: xmlConfigSample

import org.ehcache.CacheManager; //导入方法依赖的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

示例14: testWriteBehind

import org.ehcache.CacheManager; //导入方法依赖的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

示例15: testXACacheWithXMLConfig

import org.ehcache.CacheManager; //导入方法依赖的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


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