本文整理了Java中org.ehcache.Cache.remove()
方法的一些代码示例,展示了Cache.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.remove()
方法的具体详情如下:
包路径:org.ehcache.Cache
类名称:Cache
方法名:remove
[英]Removes the value, if any, associated with the provided key.
[中]删除与提供的键关联的值(如果有)。
代码示例来源:origin: ehcache/ehcache3
private void condRemove(Cache<Long, String> cache, String value, boolean addToCacheRecords) {
cache.remove(KEY, value);
if (addToCacheRecords) {
cacheRecords.add(new Record(KEY, null));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testRemove2ArgsWithNoCacheEntry_should_not_call_writer() throws Exception {
doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1));
testCache.remove(1, "one");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testRemove2ArgsWithNotMatchingCacheEntry_should_not_call_writer() throws Exception {
doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1));
testCache.put(1, "un");
testCache.remove(1, "one");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testRemoveWithWriterException() throws Exception {
doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1));
try {
testCache.remove(1);
fail("expected CacheWritingException");
} catch (CacheWritingException ex) {
// expected
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
@SuppressWarnings("unchecked")
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore_notEquals() throws Exception {
testCache.put(1, "un");
reset(cacheLoaderWriter);
assertThat(testCache.remove(1, "one"), is(false));
verifyZeroInteractions(cacheLoaderWriter);
}
代码示例来源:origin: ehcache/ehcache3
@Test
@SuppressWarnings("unchecked")
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore() throws Exception {
testCache.put(1, "un");
reset(cacheLoaderWriter);
assertThat(testCache.remove(1, "un"), is(true));
verify(cacheLoaderWriter, times(1)).delete(eq(1));
verifyNoMoreInteractions(cacheLoaderWriter);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInSor_notEquals() throws Exception {
when(cacheLoaderWriter.load(eq(1))).thenAnswer((Answer) invocation -> "un");
assertThat(testCache.containsKey(1), is(false));
assertThat(testCache.remove(1, "one"), is(false));
verify(cacheLoaderWriter, times(1)).load(eq(1));
verifyNoMoreInteractions(cacheLoaderWriter);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_absent() throws Exception {
when(cacheLoaderWriter.load(eq(1))).thenAnswer((Answer) invocation -> null);
assertThat(testCache.containsKey(1), is(false));
assertThat(testCache.remove(1, "one"), is(false));
verify(cacheLoaderWriter, times(1)).load(eq(1));
verifyNoMoreInteractions(cacheLoaderWriter);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInSor() throws Exception {
when(cacheLoaderWriter.load(eq(1))).thenAnswer((Answer) invocation -> "un");
assertThat(testCache.containsKey(1), is(false));
assertThat(testCache.remove(1, "un"), is(true));
verify(cacheLoaderWriter, times(1)).load(eq(1));
verify(cacheLoaderWriter, times(1)).delete(eq(1));
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testRemove2ArgsWithWriterException_should_call_writer() throws Exception {
doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1));
testCache.put(1, "one");
try {
testCache.remove(1, "one");
fail("expected CacheWritingException");
} catch (CacheWritingException ex) {
// expected
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getRemovals() throws Exception {
cache.put(1L, "a");
cache.remove(1L);
assertThat(onHeap.getRemovals()).isEqualTo(1L);
assertStat("OnHeap:RemovalCount").isEqualTo(1L);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void removeKV() {
expect(cache.remove(1, "a")).isFalse();
changesOf(0, 1, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
expect(cache.remove(1, "xxx")).isFalse();
changesOf(0, 1, 0, 0); // FIXME The cache counts a hit here
expect(cache.remove(1, "a")).isTrue();
changesOf(1, 0, 0, 1);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void removeKV() {
expect(cache.remove(1, "a")).isFalse();
changesOf(0, 1, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
expect(cache.remove(1, "xxx")).isFalse();
changesOf(1, 0, 0, 0);
expect(cache.remove(1, "a")).isTrue();
changesOf(1, 0, 0, 1);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getRemovals() {
cache.put(1L, "a");
cache.remove(1L);
assertThat(onHeap.getRemovals()).isEqualTo(0L);
assertNoStat("OnHeap:RemovalCount");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void remove() {
cache.remove(1);
changesOf(0, 0, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
cache.remove(1);
changesOf(0, 0, 0, 1);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void remove() {
cache.remove(1);
changesOf(0, 0, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
cache.remove(1);
changesOf(0, 0, 0, 1);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testSimpleRemove2Args() throws Exception {
Cache<Number, CharSequence> testCache = cacheManager.createCache("testCache", newCacheConfigurationBuilder(Number.class, CharSequence.class, heap(10)));
testCache.put(1, "one");
assertThat(testCache.remove(1, "one_"), is(false));
assertThat(testCache.get(1), is(notNullValue()));
assertThat(testCache.remove(1, "one"), is(true));
assertThat(testCache.get(1), is(nullValue()));
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testSimplePutWithExpiry_remove2Args() throws Exception {
insert(testCache, getEntries());
assertThat(cacheSize(testCache), is(2));
manualTimeSource.setTimeMillis(1001);
assertThat(testCache.remove(1, "one"), is(false));
assertThat(testCache.get(1), is(nullValue()));
assertThat(testCache.remove(2, "two"), is(false));
assertThat(testCache.get(2), is(nullValue()));
}
代码示例来源:origin: ehcache/ehcache3
@SuppressWarnings("unchecked")
@Exposed
public void remove(@Named("key") Object key) {
Object convertedKey = convert(key, cacheBinding.getCache().getRuntimeConfiguration().getKeyType());
cacheBinding.getCache().remove(convertedKey);
}
代码示例来源:origin: ehcache/ehcache3
@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()));
}
内容来源于网络,如有侵权,请联系作者删除!