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


Java CacheManager.getCache方法代码示例

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


在下文中一共展示了CacheManager.getCache方法的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: testTieredStore

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testTieredStore() throws Exception {
  CacheConfiguration<Long, String> tieredCacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).disk(10L, MemoryUnit.MB))
      .build();

  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .with(new CacheManagerPersistenceConfiguration(new File(System.getProperty("java.io.tmpdir") + "/tiered-cache-data")))
      .withCache("tiered-cache", tieredCacheConfiguration).build(true);

  Cache<Long, String> tieredCache = cacheManager.getCache("tiered-cache", Long.class, String.class);

  tieredCache.put(1L, "one");

  assertThat(tieredCache.get(1L), equalTo("one")); // probably coming from disk
  assertThat(tieredCache.get(1L), equalTo("one")); // probably coming from heap

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

示例3: eventsTest

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

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

示例5: main

import org.ehcache.CacheManager; //导入方法依赖的package包/类
public static void main(String[] args){
    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("preConfigured",
                    CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, String.class))
            .build(true);

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

    Cache<Long, TestData> myCache = cacheManager.createCache("myCache",
            CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, TestData.class));
    Cache<Long, TestData2> myCache2 = cacheManager.createCache("myCache2",
            CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, TestData2.class));

    TestData data=new TestData();
    myCache.put(1L, data);
    myCache.put(1L, data);
    myCache.put(1L,new TestData());
    myCache.put(1L, data);
    myCache2.put(2l,data.testData2);
    data.a=30;
    data.testData2.a=50;
    TestData value = myCache.get(1L);
    
    System.out.println(value);

    cacheManager.close();
}
 
开发者ID:xuerong,项目名称:MMServerEngine,代码行数:29,代码来源:TestEhcache.java

示例6: diskStore

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void diskStore() throws Exception {
  // tag::diskStore[]
  CacheManager cacheManager
      = CacheManagerBuilder.newCacheManagerBuilder()
      .using(PooledExecutionServiceConfigurationBuilder.newPooledExecutionServiceConfigurationBuilder() // <1>
          .defaultPool("dflt", 0, 10)
          .pool("defaultDiskPool", 1, 3)
          .pool("cache2Pool", 2, 2)
          .build())
      .with(new CacheManagerPersistenceConfiguration(new File(getStoragePath(), "myData")))
      .withDefaultDiskStoreThreadPool("defaultDiskPool") // <2>
      .withCache("cache1",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .heap(10, EntryUnit.ENTRIES)
                  .disk(10L, MemoryUnit.MB)))
      .withCache("cache2",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .heap(10, EntryUnit.ENTRIES)
                  .disk(10L, MemoryUnit.MB))
              .withDiskStoreThreadPool("cache2Pool", 2)) // <3>
      .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();
  // end::diskStore[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:34,代码来源:ThreadPools.java

示例7: testRemoveAll_without_cache_writer

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testRemoveAll_without_cache_writer() throws Exception {
  CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
      heap(100));
  CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();

  CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
  CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);

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

  for (int i = 0; i < 3; i++) {
    myCache.put("key" + i, "value" + i);
  }

  Set<String> fewKeysSet = new HashSet<String>() {
    {
      add("key0");
      add("key2");
    }
  };
  // the call to removeAll
  myCache.removeAll(fewKeysSet);

  for (int i = 0; i < 3; i++) {
    if (i == 0 || i == 2) {
      assertThat(myCache.get("key" + i), is(nullValue()));
    } else {
      assertThat(myCache.get("key" + i), is("value" + i));
    }
  }

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

示例8: registerListenerAtRuntime

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void registerListenerAtRuntime() {
  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
          ResourcePoolsBuilder.heap(10L)))
      .build(true);

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

  // tag::registerListenerAtRuntime[]
  ListenerObject listener = new ListenerObject(); // <1>
  cache.getRuntimeConfiguration().registerCacheEventListener(listener, EventOrdering.ORDERED,
      EventFiring.ASYNCHRONOUS, EnumSet.of(EventType.CREATED, EventType.REMOVED)); // <2>

  cache.put(1L, "one");
  cache.put(2L, "two");
  cache.remove(1L);
  cache.remove(2L);

  cache.getRuntimeConfiguration().deregisterCacheEventListener(listener); // <3>

  cache.put(1L, "one again");
  cache.remove(1L);
  // end::registerListenerAtRuntime[]

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

示例9: testOffHeapInOsgi

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

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

  cache.put(42L, "I am out of heap!!");

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

示例10: updateResourcesAtRuntime

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void updateResourcesAtRuntime() throws InterruptedException {
  ListenerObject listener = new ListenerObject();
  CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
    .newEventListenerConfiguration(listener, EventType.EVICTED).unordered().synchronous();

  CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
    ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10L, EntryUnit.ENTRIES))
    .add(cacheEventListenerConfiguration)
    .build();

  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
    .build(true);

  Cache<Long, String> cache = cacheManager.getCache("cache", Long.class, String.class);
  for(long i = 0; i < 20; i++ ){
    cache.put(i, "Hello World");
  }
  assertThat(listener.evicted(), is(10));

  cache.clear();
  listener.resetEvictionCount();

  // tag::updateResourcesAtRuntime[]
  ResourcePools pools = ResourcePoolsBuilder.newResourcePoolsBuilder().heap(20L, EntryUnit.ENTRIES).build(); // <1>
  cache.getRuntimeConfiguration().updateResourcePools(pools); // <2>
  assertThat(cache.getRuntimeConfiguration().getResourcePools()
    .getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L));
  // end::updateResourcesAtRuntime[]

  for(long i = 0; i < 20; i++ ){
    cache.put(i, "Hello World");
  }
  assertThat(listener.evicted(), is(0));

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

示例11: actionCall

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void actionCall() throws Exception {
  // tag::actionCall[]
  CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))
      .build();

  CacheManager cacheManager = null;
  try {
    ManagementRegistryService managementRegistry = new DefaultManagementRegistryService();
    cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
        .withCache("aCache", cacheConfiguration)
        .using(managementRegistry)
        .build(true);

    Cache<Long, String> aCache = cacheManager.getCache("aCache", Long.class, String.class);
    aCache.put(0L, "zero"); // <1>

    Context context = StatsUtil.createContext(managementRegistry); // <2>

    managementRegistry.withCapability("ActionsCapability") // <3>
        .call("clear")
        .on(context)
        .build()
        .execute();

    Assert.assertThat(aCache.get(0L), Matchers.is(Matchers.nullValue())); // <4>
  }
  finally {
    if(cacheManager != null) cacheManager.close();
  }
  // end::actionCall[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:33,代码来源:ManagementTest.java

示例12: testGetAll_with_cache_loader

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testGetAll_with_cache_loader() throws Exception {
  CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
      heap(100));
  CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();

  CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
  CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
  when(cacheLoaderWriter.load(ArgumentMatchers.any())).thenThrow(new RuntimeException("We should not have called .load() but .loadAll()"));
  when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
  CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
  CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);

  when(cacheLoaderWriter.loadAll(argThat(IsCollectionContaining.<String>hasItem("key0")))).thenReturn(new HashMap(){{put("key0","value0");}});
  when(cacheLoaderWriter.loadAll(argThat(IsCollectionContaining.<String>hasItem("key2")))).thenReturn(new HashMap(){{put("key2","value2");}});

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

  Set<String> fewKeysSet = new HashSet<String>() {
    {
      add("key0");
      add("key2");
    }
  };
  // the call to getAll
  Map<String, String> fewEntries = myCache.getAll(fewKeysSet);

  assertThat(fewEntries.size(), is(2));
  assertThat(fewEntries.get("key0"), is("value0"));
  assertThat(fewEntries.get("key2"), is("value2"));

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

示例13: testTpsLimit

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
@Ignore
public void testTpsLimit() throws SyntaxException {
  CacheConfigurationBuilder<Long, byte[]> builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, byte[].class,
      newResourcePoolsBuilder().heap(250000, EntryUnit.ENTRIES).build());

  final CacheManager cacheManager = newCacheManagerBuilder()
      .withCache("one", builder.build())
      .build(true);

  final Cache<Long, byte[]> one = cacheManager.getCache("one", Long.class, byte[].class);

  ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig().threads(4).timeout(50, MINUTES);

  ObjectGenerator<Long> keyGenerator = new LongGenerator();
  ObjectGenerator<byte[]> valueGenerator = fixedLengthByteArray(1000);

  EhcacheResult[] resultsReported = new EhcacheResult[] { GET, PUT, MISS };

  Scenario scenario = scenario("Test phase").exec(
      put(keyGenerator, valueGenerator, sequentially(), 50000, singletonList(cache("one", one)))
  );

  System.out.println("----------> Test phase");
  Runner.setUp(scenario)
      .executed(once(4, instances), during(10, seconds))
      .config(concurrency,
          ReportingConfig.report(EhcacheResult.class, resultsReported)
              .log(text(), html()))
      .config(cacheConfig(Long.class, byte[].class).cache("one", one)
      )
      .start();
  System.out.println("----------> Done");

  cacheManager.close();
}
 
开发者ID:aurbroszniowski,项目名称:Rainfall-ehcache,代码行数:37,代码来源:PerfTest3.java

示例14: events

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void events() throws Exception {
  // tag::events[]
  CacheManager cacheManager
      = CacheManagerBuilder.newCacheManagerBuilder()
      .using(PooledExecutionServiceConfigurationBuilder.newPooledExecutionServiceConfigurationBuilder() // <1>
          .pool("defaultEventPool", 1, 3)
          .pool("cache2Pool", 2, 2)
          .build())
      .withDefaultEventListenersThreadPool("defaultEventPool") // <2>
      .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")) // <3>
      .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();
  // end::events[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:32,代码来源:ThreadPools.java

示例15: testMultiThreadedSyncNotifications

import org.ehcache.CacheManager; //导入方法依赖的package包/类
@Test
public void testMultiThreadedSyncNotifications() throws InterruptedException {
  CacheConfiguration<Number, Number> cacheConfiguration = newCacheConfigurationBuilder(Number.class, Number.class,
      newResourcePoolsBuilder()
          .heap(10L, EntryUnit.ENTRIES))
      .build();

  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
      .build(true);
  Cache<Number, Number> cache = cacheManager.getCache("cache", Number.class, Number.class);
  cache.getRuntimeConfiguration()
      .registerCacheEventListener(listener1, EventOrdering.UNORDERED, EventFiring.SYNCHRONOUS, EnumSet
          .of(EventType.CREATED, EventType.EVICTED));

  Thread[] operators = new Thread[10];
  for (int i = 0; i < 10; i++) {
    operators[i] = new Thread(new CachePutOperator(cache, i), "CACHE-PUT-OPERATOR_" + i);
    operators[i].start();
  }
  for (int i = 0; i < 10; i++) {
    operators[i].join();
  }

  int entryCount = 0;
  for (Cache.Entry<Number, Number> entry : cache) {
    entryCount++;
  }

  cacheManager.close();

  assertEquals(100, listener1.created.get());
  assertEquals(100 - entryCount, listener1.evicted.get());
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:34,代码来源:EventNotificationTest.java


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