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


Java Cache.clear方法代码示例

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


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

示例1: testAtomicsWithoutLoaderWriter

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testAtomicsWithoutLoaderWriter() throws Exception {
  CacheConfigurationBuilder<Long, String> cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      newResourcePoolsBuilder()
                  .heap(10, EntryUnit.ENTRIES)
                  .offheap(10, MemoryUnit.MB)
              )
      .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(1)));

  cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("txCache1", cacheConfigurationBuilder.add(new XAStoreConfiguration("txCache1")).build())
      .using(new DefaultTimeSourceService(new TimeSourceConfiguration(testTimeSource)))
      .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class))
      .build(true);

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

  putIfAbsentAssertions(transactionManager, txCache1);
  txCache1.clear();
  remove2ArgsAssertions(transactionManager, txCache1);
  txCache1.clear();
  replace2ArgsAssertions(transactionManager, txCache1);
  txCache1.clear();
  replace3ArgsAssertions(transactionManager, txCache1);
  txCache1.clear();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:XACacheTest.java

示例2: testClear

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testClear() throws Exception {
  Cache<Number, CharSequence> testCache = cacheManager.createCache("testCache", newCacheConfigurationBuilder(Number.class, CharSequence.class, heap(10)));

  testCache.put(1, "one");
  testCache.put(2, "two");

  testCache.clear();

  assertThat(testCache.get(1), is(nullValue()));
  assertThat(testCache.get(2), is(nullValue()));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:13,代码来源:SimpleEhcacheTest.java

示例3: testAtomicsWithLoaderWriter

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testAtomicsWithLoaderWriter() throws Exception {
  SampleLoaderWriter<Long, String> loaderWriter = new SampleLoaderWriter<>();

  CacheConfigurationBuilder<Long, String> cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      newResourcePoolsBuilder()
                  .heap(10, EntryUnit.ENTRIES)
                  .offheap(10, MemoryUnit.MB))
      .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(1)))
      .withLoaderWriter(loaderWriter);

  cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("txCache1", cacheConfigurationBuilder.add(new XAStoreConfiguration("txCache1")).build())
      .using(new DefaultTimeSourceService(new TimeSourceConfiguration(testTimeSource)))
      .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class))
      .build(true);

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

  putIfAbsentAssertions(transactionManager, txCache1);
  txCache1.clear();
  loaderWriter.clear();
  remove2ArgsAssertions(transactionManager, txCache1);
  txCache1.clear();
  loaderWriter.clear();
  replace2ArgsAssertions(transactionManager, txCache1);
  txCache1.clear();
  loaderWriter.clear();
  replace3ArgsAssertions(transactionManager, txCache1);
  txCache1.clear();
  loaderWriter.clear();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:33,代码来源:XACacheTest.java

示例4: updateResourcesAtRuntime

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

示例5: basicCacheCRUD

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void basicCacheCRUD() throws Exception {
  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
      = CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER.getConnectionURI().resolve("/crud-cm"))
          .autoCreate()
          .defaultServerResource("primary-server-resource"));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  try {
    CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder()
            .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 1, MemoryUnit.MB))).build();

    Cache<Long, String> cache = cacheManager.createCache("clustered-cache", config);
    cache.put(1L, "The one");
    assertThat(cache.containsKey(2L), is(false));
    cache.put(2L, "The two");
    assertThat(cache.containsKey(2L), is(true));
    cache.put(1L, "Another one");
    cache.put(3L, "The three");
    assertThat(cache.get(1L), equalTo("Another one"));
    assertThat(cache.get(2L), equalTo("The two"));
    assertThat(cache.get(3L), equalTo("The three"));
    cache.remove(1L);
    assertThat(cache.get(1L), is(nullValue()));

    cache.clear();
    assertThat(cache.get(1L), is(nullValue()));
    assertThat(cache.get(2L), is(nullValue()));
    assertThat(cache.get(3L), is(nullValue()));
  } finally {
    cacheManager.close();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:37,代码来源:BasicClusteredCacheOpsTest.java


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