javax.cache.Cache.remove()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(236)

本文整理了Java中javax.cache.Cache.remove()方法的一些代码示例,展示了Cache.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.remove()方法的具体详情如下:
包路径:javax.cache.Cache
类名称:Cache
方法名:remove

Cache.remove介绍

[英]Removes the mapping for a key from this cache if it is present.

More formally, if this cache contains a mapping from key k to value v such that (key==null ? k==null : key.equals(k)), that mapping is removed. (The cache can contain at most one such mapping.)

Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key.

The cache will not contain a mapping for the specified key once the call returns.
[中]从缓存中删除密钥的映射(如果存在)。
更正式地说,如果此缓存包含从键k到值v的映射,并且(key==null ? k==null : key.equals(k)),则该映射将被删除。(缓存最多可以包含一个这样的映射。)
如果此缓存以前与密钥关联,则返回true;如果缓存不包含密钥的映射,则返回false。
一旦调用返回,缓存将不包含指定键的映射。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void evict(Object key) {
  this.cache.remove(key);
}

代码示例来源:origin: ehcache/ehcache3

private void innerClear() {
  cache.get(1); // one miss
  cache.getAll(asSet(1, 2, 3)); // 3 misses
  cache.put(1, "a"); // one put
  cache.put(1, "b"); // one put and update
  cache.putAll(Collections.singletonMap(2, "b")); // 1 put
  cache.get(1); // one hit
  cache.remove(1); // one remove
  cache.removeAll(); // one remove
  changesOf(1, 4, 3, 2);

  cacheStatistics.clear();
  changesOf(-1, -4, -3, -2);
 }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void removeFromCache(Object key, SharedSessionContractImplementor session) {
  underlyingCache.remove( key );
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void evictData(Object key) {
  underlyingCache.remove( key );
}

代码示例来源:origin: org.springframework/spring-context-support

@Override
public void evict(Object key) {
  this.cache.remove(key);
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public <K> boolean remove(K key) {
  return jCache.remove(key);
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public void apply(IgniteFuture<Object> future) {
    // Reset distributed cleanup flag.
    metaCache.remove(CLEANUP_NODE_ID);
    // Reset local cleanup flag.
    cleanupFlags.remove(dataCacheName);
  }
}

代码示例来源:origin: killbill/killbill

@Override
public boolean remove(final K key) {
  if (isKeyInCache(key)) {
    cache.remove(key);
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: killbill/killbill

@Override
public V remove(final K key) throws CacheException {
  V previousValue;
  while (true) {
    previousValue = cache.get(key);
    if (previousValue == null) {
      break;
    } else {
      if (cache.remove(key)) {
        break;
      }
    }
  }
  return previousValue;
}

代码示例来源:origin: requery/requery

@Override
public void invalidate(Class<?> type, Object key) {
  Cache cache = getCache(type);
  if (cache != null && !cache.isClosed()) {
    cache.remove(key);
  }
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void test_getCacheRemovals() throws Exception {
 heapCache.put("key0", "value");
 heapCache.put("key1", "value");
 heapCache.put("key2", "value");
 heapCache.put("key3", "value");
 heapCache.put("key4", "value");
 heapCache.remove("key0");
 heapCache.remove("key1");
 heapCache.remove("key2");
 heapCache.remove("key3");
 heapCache.remove("key4");
 assertThat(heapStatistics.getCacheRemovals(), is(5L));
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_absent() throws Exception {
 when(cacheLoader.load(eq(1))).thenAnswer(invocation -> null);
 assertThat(testCache.containsKey(1), is(false));
 assertThat(testCache.remove(1, "one"), is(false));
 verifyZeroInteractions(cacheLoader);
 verifyZeroInteractions(cacheWriter);
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInSor() throws Exception {
 when(cacheLoader.load(eq(1))).thenAnswer(invocation -> "un");
 assertThat(testCache.containsKey(1), is(false));
 assertThat(testCache.remove(1, "un"), is(false));
 verifyZeroInteractions(cacheLoader);
 verifyZeroInteractions(cacheWriter);
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void test_getAverageRemoveTime() throws Exception {
 assertThat(heapStatistics.getAverageRemoveTime(), is(0.0f));
 heapCache.put("key0", "value");
 heapCache.put("key1", "value");
 heapCache.put("key2", "value");
 heapCache.put("key3", "value");
 heapCache.put("key4", "value");
 heapCache.remove("key0");
 heapCache.remove("key1");
 heapCache.remove("key2");
 heapCache.remove("key3");
 heapCache.remove("key4");
 assertFor(1100L, () -> heapStatistics.getAverageRemoveTime(), is(not(0.0f)));
 assertThat(heapStatistics.getAverageRemoveTime(), greaterThan(0.0f));
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore() throws Exception {
 testCache.put(1, "un");
 reset(cacheWriter);
 assertThat(testCache.remove(1, "un"), is(true));
 verifyZeroInteractions(cacheLoader);
 verify(cacheWriter, times(1)).delete(eq(1));
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore_notEquals() throws Exception {
 testCache.put(1, "un");
 reset(cacheWriter);
 assertThat(testCache.remove(1, "one"), is(false));
 verifyZeroInteractions(cacheLoader);
 verifyZeroInteractions(cacheWriter);
}

代码示例来源: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 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: pippo-java/pippo

@Override
public void delete(String sessionId) {
  this.sessions.remove(sessionId);
}

代码示例来源:origin: apache/cxf

@Override
public ServerAuthorizationCodeGrant removeCodeGrant(String code) throws OAuthServiceException {
  ServerAuthorizationCodeGrant grant = getCodeGrant(code);
  if (grant != null) {
    grantCache.remove(code);
  }
  return grant;
}

相关文章