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


Java CacheManager类代码示例

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


CacheManager类属于org.ehcache包,在下文中一共展示了CacheManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.ehcache.CacheManager; //导入依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating cache manager via XML resource");
  Configuration xmlConfig = new XmlConfiguration(BasicXML.class.getResource("/ehcache.xml"));
  try (CacheManager cacheManager = newCacheManager(xmlConfig)) {
    cacheManager.init();

    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:BasicXML.java

示例2: configure

import org.ehcache.CacheManager; //导入依赖的package包/类
@Override
protected void configure() {
    //bindings that parent modules must provide
    requireBinding(CacheManager.class);
    requireBinding(StatisticConfigurationService.class);
    requireBinding(StroomPropertyService.class);

    //simple binds
    bind(CacheConfigurationService.class).to(CacheConfigurationServiceImpl.class);
    bind(CacheFactory.class).to(CacheFactoryImpl.class);
    bind(ClusterLockService.class).to(ClusterLockServiceImpl.class);
    bind(StatisticConfigurationValidator.class).to(StatisticConfigurationValidatorImpl.class);
    bind(StatisticsService.class).to(HBaseStatisticsService.class);
    bind(TaskManager.class).to(TaskManagerImpl.class);
    bind(UniqueIdCache.class).to(UniqueIdCacheImpl.class);
    bind(UniqueIdForwardMapTable.class).to(HBaseUniqueIdForwardMapTable.class);
    bind(UniqueIdReverseMapTable.class).to(HBaseUniqueIdReverseMapTable.class);

    //providers
    bind(UniqueIdGenerator.class).toProvider(UniqueIdGeneratorProvider.class).asEagerSingleton();

    //singletons
    bind(EventStoreTableFactory.class).to(HBaseEventStoreTableFactory.class).asEagerSingleton();
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:25,代码来源:StroomStatsHbaseClientModule.java

示例3: testDoubleInit

import org.ehcache.CacheManager; //导入依赖的package包/类
@Test
public void testDoubleInit() throws Exception {
  ehcacheShiroManager.init();
  CacheManager firstCacheManager = ehcacheShiroManager.getCacheManager();
  Assert.assertNotNull(firstCacheManager);

  ehcacheShiroManager.setCacheManagerConfigFile("notValidPath");
  ehcacheShiroManager.init();
  CacheManager secondCacheManager = ehcacheShiroManager.getCacheManager();
  Assert.assertNotNull(secondCacheManager);

  Assert.assertEquals(firstCacheManager, secondCacheManager);
  Assert.assertSame(firstCacheManager, secondCacheManager);

  ehcacheShiroManager.destroy();
}
 
开发者ID:ehcache,项目名称:ehcache-shiro,代码行数:17,代码来源:ArbitraryCacheManagerTest.java

示例4: testArbitraryCacheManager

import org.ehcache.CacheManager; //导入依赖的package包/类
/**
 * Test showing issues:
 * <p>
 * https://github.com/ehcache/ehcache-shiro/issues/12
 * https://github.com/ehcache/ehcache-shiro/issues/13
 *
 * @throws Exception
 */
@Test
public void testArbitraryCacheManager() throws Exception {
  ehcacheShiroManager.init();
  CacheManager firstCacheManager = ehcacheShiroManager.getCacheManager();
  Assert.assertNotNull(firstCacheManager);

  ehcacheShiroManager.setCacheManager(cacheManager);
  CacheManager secondCacheManager = ehcacheShiroManager.getCacheManager();
  Assert.assertNotSame(firstCacheManager, secondCacheManager);
  Assert.assertNotEquals(firstCacheManager, secondCacheManager);

  ehcacheShiroManager.destroy();

  Assert.assertEquals(Status.UNINITIALIZED, firstCacheManager.getStatus());
  Assert.assertEquals(Status.AVAILABLE, secondCacheManager.getStatus());
}
 
开发者ID:ehcache,项目名称:ehcache-shiro,代码行数:25,代码来源:ArbitraryCacheManagerTest.java

示例5: 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

示例6: main

import org.ehcache.CacheManager; //导入依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating cache manager programmatically");
  try (CacheManager cacheManager = newCacheManagerBuilder()
    .withCache("basicCache",
      newCacheConfigurationBuilder(Long.class, String.class, heap(100).offheap(1, MB)))
    .build(true)) {
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:BasicProgrammatic.java

示例7: main

import org.ehcache.CacheManager; //导入依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating clustered cache manager");
  final URI uri = create("terracotta://localhost:9510/clustered");
  try (CacheManager cacheManager = newCacheManagerBuilder()
          .with(cluster(uri).autoCreate().defaultServerResource("default-resource"))
          .withCache("basicCache",
                  newCacheConfigurationBuilder(Long.class, String.class,
                          heap(100).offheap(1, MB).with(clusteredDedicated(5, MB))))
          .build(true)) {
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:20,代码来源:ClusteredProgrammatic.java

示例8: main

import org.ehcache.CacheManager; //导入依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating clustered cache manager from XML");
  final URL myUrl = ClusteredXML.class.getResource("/ehcache.xml");
  Configuration xmlConfig = new XmlConfiguration(myUrl);
  try (CacheManager cacheManager = newCacheManager(xmlConfig)) {
    cacheManager.init();
    
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);
    
    LOGGER.info("Getting from cache");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:ClusteredXML.java

示例9: createCacheManager

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

示例10: testFilledBatchedIsWritten

import org.ehcache.CacheManager; //导入依赖的package包/类
@Test
public void testFilledBatchedIsWritten() throws Exception {
  WriteBehindTestLoaderWriter<String, String> loaderWriter = new WriteBehindTestLoaderWriter<>();
  CacheLoaderWriterProvider cacheLoaderWriterProvider = getMockedCacheLoaderWriterProvider(loaderWriter);

  try (CacheManager cacheManager = managerBuilder().using(cacheLoaderWriterProvider).build(true)) {
    Cache<String, String> testCache = cacheManager.createCache("testFilledBatchedIsWritten", configurationBuilder()
      .add(newBatchedWriteBehindConfiguration(Long.MAX_VALUE, SECONDS, 2).build())
      .build());

    CountDownLatch latch = new CountDownLatch(2);
    loaderWriter.setLatch(latch);

    testCache.put("key1", "value");
    testCache.put("key2", "value");

    if (latch.await(10, SECONDS)) {
      assertThat(loaderWriter.getValueList("key1"), contains("value"));
      assertThat(loaderWriter.getValueList("key2"), contains("value"));
    } else {
      fail("Took too long to write, assuming batch is not going to be written");
    }
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:AbstractWriteBehindTestBase.java

示例11: testOffHeapClientClass

import org.ehcache.CacheManager; //导入依赖的package包/类
@Test
public void testOffHeapClientClass() {
  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .withClassLoader(getClass().getClassLoader())
      .withCache("myCache", newCacheConfigurationBuilder(Long.class, Order.class, newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).offheap(2, MemoryUnit.MB))
          .build())
      .build(true);

  Cache<Long, Order> cache = cacheManager.getCache("myCache", Long.class, Order.class);

  Order order = new Order(42L);
  cache.put(42L, order);

  assertTrue(cache.get(42L) instanceof Order);

  cache.replace(42L, order, new Order(-1L));

  assertEquals(-1L, cache.get(42L).id);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:OffHeapOsgiTest.java

示例12: testCoaslecedWritesAreNotSeen

import org.ehcache.CacheManager; //导入依赖的package包/类
@Test
public void testCoaslecedWritesAreNotSeen() throws InterruptedException {
  WriteBehindTestLoaderWriter<String, String> loaderWriter = new WriteBehindTestLoaderWriter<>();
  CacheLoaderWriterProvider cacheLoaderWriterProvider = getMockedCacheLoaderWriterProvider(loaderWriter);

  try (CacheManager cacheManager = managerBuilder().using(cacheLoaderWriterProvider).build(true)) {
    Cache<String, String> testCache = cacheManager.createCache("testCoaslecedWritesAreNotSeen", configurationBuilder()
      .add(newBatchedWriteBehindConfiguration(Long.MAX_VALUE, SECONDS, 2).enableCoalescing().build())
      .build());

    CountDownLatch latch = new CountDownLatch(2);
    loaderWriter.setLatch(latch);

    testCache.put("keyA", "value1");
    testCache.put("keyA", "value2");

    testCache.put("keyB", "value3");

    latch.await();
    assertThat(loaderWriter.getValueList("keyA"), contains("value2"));
    assertThat(loaderWriter.getValueList("keyB"), contains("value3"));
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:AbstractWriteBehindTestBase.java

示例13: testOverSizedObjectPutFailsWithOnHeapAsAuthority

import org.ehcache.CacheManager; //导入依赖的package包/类
@Test
public void testOverSizedObjectPutFailsWithOnHeapAsAuthority() {
  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .withDefaultSizeOfMaxObjectSize(500, MemoryUnit.B).build(true);

  CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder
      .newCacheConfigurationBuilder(String.class, String.class,
          newResourcePoolsBuilder()
              .heap(100, MemoryUnit.KB).build())
      .build();

  Cache<String, String> cache = cacheManager.createCache("cache",
      cacheConfiguration);

  cache.put("key1", getOverSizedObject());
  assertThat(cache.get("key1"), nullValue());

  cache.put("key1", "value1");
  cache.replace("key1", getOverSizedObject());
  assertThat(cache.get("key1"), nullValue());

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

示例14: testEventOrderForUpdateThatTriggersEviction

import org.ehcache.CacheManager; //导入依赖的package包/类
@Test
public void testEventOrderForUpdateThatTriggersEviction () {
  CacheConfiguration<Long, SerializableObject> cacheConfiguration = newCacheConfigurationBuilder(Long.class, SerializableObject.class,
      newResourcePoolsBuilder()
          .heap(1L, EntryUnit.ENTRIES).offheap(1l, MemoryUnit.MB).build()).build();

  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
      .build(true);
  Cache<Long, SerializableObject> cache = cacheManager.getCache("cache", Long.class, SerializableObject.class);
  cache.getRuntimeConfiguration().registerCacheEventListener(listener1, EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet
      .of(EventType.EVICTED, EventType.CREATED, EventType.UPDATED, EventType.REMOVED));
  SerializableObject object1 = new SerializableObject(0xAAE60);     // 700 KB
  SerializableObject object2 = new SerializableObject(0xDBBA0);     // 900 KB

  cache.put(1L, object1);
  cache.put(1L, object2);
  assertThat(listener1.eventTypeHashMap.get(EventType.EVICTED), lessThan(listener1.eventTypeHashMap.get(EventType.CREATED)));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:EventNotificationTest.java

示例15: testAddingWriteBehindConfigurationAtCacheLevel

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


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