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


Java Cache.remove方法代码示例

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


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

示例1: putIfAbsentAssertions

import org.ehcache.Cache; //导入方法依赖的package包/类
private void putIfAbsentAssertions(BitronixTransactionManager transactionManager, Cache<Long, String> txCache1) throws Exception {
  transactionManager.begin();
  {
    assertThat(txCache1.putIfAbsent(1L, "one"), is(nullValue()));
    assertThat(txCache1.putIfAbsent(1L, "un"), equalTo("one"));
  }
  transactionManager.commit();

  assertMapping(transactionManager, txCache1, 1L, "one");

  transactionManager.begin();
  {
    assertThat(txCache1.putIfAbsent(1L, "eins"), equalTo("one"));
    txCache1.remove(1L);
    assertThat(txCache1.putIfAbsent(1L, "een"), is(nullValue()));
  }
  transactionManager.commit();

  assertMapping(transactionManager, txCache1, 1L, "een");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:XACacheTest.java

示例2: replace2ArgsAssertions

import org.ehcache.Cache; //导入方法依赖的package包/类
private void replace2ArgsAssertions(BitronixTransactionManager transactionManager, Cache<Long, String> txCache1) throws Exception {
  transactionManager.begin();
  {
    assertThat(txCache1.replace(1L, "one"), is(nullValue()));
    txCache1.put(1L, "un");
    assertThat(txCache1.replace(1L, "eins"), equalTo("un"));
  }
  transactionManager.commit();

  assertMapping(transactionManager, txCache1, 1L, "eins");

  transactionManager.begin();
  {
    assertThat(txCache1.replace(1L, "een"), equalTo("eins"));
    txCache1.put(1L, "un");
    assertThat(txCache1.replace(1L, "een"), equalTo("un"));
    txCache1.remove(1L);
    assertThat(txCache1.replace(1L, "one"), is(nullValue()));
    assertThat(txCache1.get(1L), is(nullValue()));
  }
  transactionManager.commit();

  assertMapping(transactionManager, txCache1, 1L, null);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:XACacheTest.java

示例3: testCacheEventListener

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

示例4: testCacheEventListenerWithMultipleListener

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

示例5: testCacheEventListener

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testCacheEventListener() {
  // tag::cacheEventListener[]
  CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
      .newEventListenerConfiguration(new ListenerObject(), EventType.CREATED, EventType.UPDATED) // <1>
      .unordered().asynchronous(); // <2>

  final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("foo",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
              .add(cacheEventListenerConfiguration) // <3>
      ).build(true);

  final Cache<String, String> cache = manager.getCache("foo", String.class, String.class);
  cache.put("Hello", "World"); // <4>
  cache.put("Hello", "Everyone"); // <5>
  cache.remove("Hello"); // <6>
  // end::cacheEventListener[]

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

示例6: testWrites

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testWrites() 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("testWrites", CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, heap(10))
      .add(newUnBatchedWriteBehindConfiguration().concurrencyLevel(3).queueSize(10).build())
      .build());

    CountDownLatch countDownLatch = new CountDownLatch(4);
    loaderWriter.setLatch(countDownLatch);
    testCache.put("test1", "test1");
    testCache.put("test2", "test2");
    testCache.put("test3", "test3");
    testCache.remove("test2");

    countDownLatch.await(2, SECONDS);

    assertThat(loaderWriter.getData().get("test1"), contains("test1"));
    assertThat(loaderWriter.getData().get("test2"), contains("test2", null));
    assertThat(loaderWriter.getData().get("test3"), contains("test3"));
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:AbstractWriteBehindTestBase.java

示例7: testBatchedDeletedKeyReturnsNull

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testBatchedDeletedKeyReturnsNull() throws Exception {
  @SuppressWarnings("unchecked")
  CacheLoaderWriter<String, String> loaderWriter = mock(CacheLoaderWriter.class);
  when(loaderWriter.load("key")).thenReturn("value");
  CacheLoaderWriterProvider cacheLoaderWriterProvider = getMockedCacheLoaderWriterProvider(loaderWriter);

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

    assertThat(testCache.get("key"), is("value"));

    testCache.remove("key");

    assertThat(testCache.get("key"), nullValue());
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:AbstractWriteBehindTestBase.java

示例8: eventListenerTest

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void eventListenerTest() {
    CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
            .newEventListenerConfiguration(new ListenerObject(), EventType.CREATED, EventType.UPDATED).unordered()
            .asynchronous();

    final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("foo",
                    CacheConfigurationBuilder
                            .newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
                            .add(cacheEventListenerConfiguration))
            .build(true);

    CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(5L))
            .withDispatcherConcurrency(10).withEventListenersThreadPool("listeners-pool").build();

    final Cache<String, String> cache = manager.getCache("foo", String.class, String.class);
    cache.put("Hello", "World");
    cache.put("Hello", "Everyone");
    cache.remove("Hello");
}
 
开发者ID:dzh,项目名称:jframe,代码行数:23,代码来源:TestEventListener.java

示例9: testSimpleRemove

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testSimpleRemove() 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.remove(1);

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

示例10: testRecoveryWithInflightTx

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

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

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

  transactionManager.begin();
  {
    txCache1.put(1L, "one");
    txCache2.put(1L, "un");
  }
  transactionManager.commit();


  transactionManager.begin();
  {
    txCache1.remove(1L);
    txCache2.remove(1L);
  }
  transactionManager.getCurrentTransaction().addTransactionStatusChangeListener((oldStatus, newStatus) -> {
    if (newStatus == Status.STATUS_PREPARED) {
      Recoverer recoverer = TransactionManagerServices.getRecoverer();
      recoverer.run();
      assertThat(recoverer.getCommittedCount(), is(0));
      assertThat(recoverer.getRolledbackCount(), is(0));
    }
  });
  transactionManager.commit();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:40,代码来源:XACacheTest.java

示例11: registerListenerAtRuntime

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

示例12: testWriteOrdering

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testWriteOrdering() 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("testWriteOrdering", configurationBuilder()
      .add(newBatchedWriteBehindConfiguration(Long.MAX_VALUE, SECONDS, 8).build())
      .build());

    CountDownLatch countDownLatch = new CountDownLatch(8);

    loaderWriter.setLatch(countDownLatch);

    testCache.remove("key");
    testCache.put("key", "value1");
    testCache.remove("key");
    testCache.put("key", "value2");
    testCache.remove("key");
    testCache.put("key", "value3");
    testCache.remove("key");
    testCache.put("key", "value4");

    countDownLatch.await(4, SECONDS);

    assertThat(loaderWriter.getData()
      .get("key"), contains(null, "value1", null, "value2", null, "value3", null, "value4"));
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:30,代码来源:AbstractWriteBehindTestBase.java

示例13: testUnBatchedDeletedKeyReturnsNull

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testUnBatchedDeletedKeyReturnsNull() throws Exception {
  final Semaphore semaphore = new Semaphore(0);

  @SuppressWarnings("unchecked")
  CacheLoaderWriter<String, String> loaderWriter = mock(CacheLoaderWriter.class);
  when(loaderWriter.load("key")).thenReturn("value");
  doAnswer(invocation -> {
    semaphore.acquire();
    return null;
  }).when(loaderWriter).delete("key");
  CacheLoaderWriterProvider cacheLoaderWriterProvider = getMockedCacheLoaderWriterProvider(loaderWriter);

  CacheManager cacheManager = managerBuilder().using(cacheLoaderWriterProvider).build(true);
  try {
    Cache<String, String> testCache = cacheManager.createCache("testUnBatchedDeletedKeyReturnsNull", configurationBuilder()
        .add(newUnBatchedWriteBehindConfiguration().build())
        .build());

    assertThat(testCache.get("key"), is("value"));

    testCache.remove("key");

    assertThat(testCache.get("key"), nullValue());
  } finally {
    semaphore.release();
    cacheManager.close();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:30,代码来源:AbstractWriteBehindTestBase.java

示例14: testUnBatchedOverwrittenKeyReturnsNewValue

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testUnBatchedOverwrittenKeyReturnsNewValue() throws Exception {
  final Semaphore semaphore = new Semaphore(0);

  @SuppressWarnings("unchecked")
  CacheLoaderWriter<String, String> loaderWriter = mock(CacheLoaderWriter.class);
  when(loaderWriter.load("key")).thenReturn("value");
  doAnswer(invocation -> {
    semaphore.acquire();
    return null;
  }).when(loaderWriter).delete("key");
  CacheLoaderWriterProvider cacheLoaderWriterProvider = getMockedCacheLoaderWriterProvider(loaderWriter);

  CacheManager cacheManager = managerBuilder().using(cacheLoaderWriterProvider).build(true);
  try {
    Cache<String, String> testCache = cacheManager.createCache("testUnBatchedOverwrittenKeyReturnsNewValue", configurationBuilder()
        .add(newUnBatchedWriteBehindConfiguration().build())
        .build());

    assertThat(testCache.get("key"), is("value"));

    testCache.remove("key");

    assertThat(testCache.get("key"), nullValue());
  } finally {
    semaphore.release();
    cacheManager.close();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:30,代码来源:AbstractWriteBehindTestBase.java

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