com.google.common.cache.Cache#invalidateAll ( )源码实例Demo

下面列出了com.google.common.cache.Cache#invalidateAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: blog   文件: GuavaCache5.java
public static void main(String[] args) throws InterruptedException {
    Cache<String,String> cache = CacheBuilder.newBuilder().build();
    Object value = new Object();
    cache.put("key1","value1");
    cache.put("key2","value2");
    cache.put("key3","value3");

    List<String> list = new ArrayList<String>();
    list.add("key1");
    list.add("key2");

    cache.invalidateAll(list);//批量清除list中全部key对应的记录
    System.out.println(cache.getIfPresent("key1"));
    System.out.println(cache.getIfPresent("key2"));
    System.out.println(cache.getIfPresent("key3"));
}
 
源代码2 项目: calcite-avatica   文件: RemoteDriverTest.java
@Test public void testStatementLifecycle() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection connection = (AvaticaConnection) getLocalConnection()) {
    Map<Integer, AvaticaStatement> clientMap = connection.statementMap;
    Cache<Integer, Object> serverMap = getLocalConnectionInternals()
        .getRemoteStatementMap(connection);
    // Other tests being run might leave statements in the cache.
    // The lock guards against more statements being cached during the test.
    serverMap.invalidateAll();
    assertEquals(0, clientMap.size());
    assertEquals(0, serverMap.size());
    Statement stmt = connection.createStatement();
    assertEquals(1, clientMap.size());
    assertEquals(1, serverMap.size());
    stmt.close();
    assertEquals(0, clientMap.size());
    assertEquals(0, serverMap.size());
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
源代码3 项目: ambari-metrics   文件: TimelineMetricsHolder.java
/**
 * Returns values from cache and clears the cache
 * @param cache
 * @param lock
 * @return
 */
private Map<String, TimelineMetrics> extractMetricsFromCacheWithLock(Cache<String, TimelineMetrics> cache, ReadWriteLock lock) {
  lock.writeLock().lock();
  Map<String, TimelineMetrics> metricsMap = new TreeMap<>(cache.asMap());
  cache.invalidateAll();
  lock.writeLock().unlock();
  return metricsMap;
}
 
源代码4 项目: calcite-avatica   文件: RemoteDriverTest.java
@Test public void testConnectionIsolation() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try {
    Cache<String, Connection> connectionMap = getLocalConnectionInternals()
        .getRemoteConnectionMap((AvaticaConnection) getLocalConnection());
    // Other tests being run might leave connections in the cache.
    // The lock guards against more connections being cached during the test.
    connectionMap.invalidateAll();

    final String sql = "select * from (values (1, 'a'))";
    assertEquals("connection cache should start empty",
        0, connectionMap.size());
    Connection conn1 = getLocalConnection();
    Connection conn2 = getLocalConnection();
    assertEquals("we now have two connections open",
        2, connectionMap.size());
    PreparedStatement conn1stmt1 = conn1.prepareStatement(sql);
    assertEquals(
        "creating a statement does not cause new connection",
        2, connectionMap.size());
    PreparedStatement conn2stmt1 = conn2.prepareStatement(sql);
    assertEquals(
        "creating a statement does not cause new connection",
        2, connectionMap.size());
    AvaticaPreparedStatement s1 = (AvaticaPreparedStatement) conn1stmt1;
    AvaticaPreparedStatement s2 = (AvaticaPreparedStatement) conn2stmt1;
    assertFalse("connection id's should be unique",
        s1.handle.connectionId.equalsIgnoreCase(s2.handle.connectionId));
    conn2.close();
    assertEquals("closing a connection closes the server-side connection",
        1, connectionMap.size());
    conn1.close();
    assertEquals("closing a connection closes the server-side connection",
        0, connectionMap.size());
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
源代码5 项目: mycore   文件: MCRCache.java
/**
 * Changes the capacity of this cache. This is the maximum number of objects that will be cached at a time. If the
 * new capacity is smaller than the current number of objects in the cache, the least recently used objects will be
 * removed from the cache.
 *
 * @param capacity
 *            the maximum number of objects this cache will hold
 */
public synchronized void setCapacity(long capacity) {
    this.capacity = capacity;
    Cache<K, MCRCacheEntry<V>> newCache = CacheBuilder.newBuilder().recordStats().maximumSize(capacity).build();
    newCache.putAll(backingCache.asMap());
    Cache<K, MCRCacheEntry<V>> oldCache = backingCache;
    backingCache = newCache;
    oldCache.invalidateAll();
}
 
源代码6 项目: apollo   文件: AbstractConfig.java
/**
 * Clear config cache
 */
protected void clearConfigCache() {
  synchronized (this) {
    for (Cache c : allCaches) {
      if (c != null) {
        c.invalidateAll();
      }
    }
    m_configVersion.incrementAndGet();
  }
}
 
源代码7 项目: emodb   文件: DefaultCacheRegistry.java
private void invalidate(InvalidationEvent event) {
    // Invalidate the actual cache.
    Cache<String, ?> cache = _cache.get();
    if (cache != null) {
        if (event.hasKeys()) {
            cache.invalidateAll(event.getKeys());
        } else {
            cache.invalidateAll();
        }
    }
    notifyListeners(event);
}
 
源代码8 项目: phoenix   文件: MetaDataEndpointImpl.java
@Override
public void clearCache(RpcController controller, ClearCacheRequest request,
        RpcCallback<ClearCacheResponse> done) {
    GlobalCache cache = GlobalCache.getInstance(this.env);
    Cache<ImmutableBytesPtr, PTable> metaDataCache =
            GlobalCache.getInstance(this.env).getMetaDataCache();
    metaDataCache.invalidateAll();
    cache.clearTenantCache();
}
 
源代码9 项目: EVCache   文件: HotKeyListener.java
private void setupHotKeyListener() {
    if(enableThrottleHotKeys.get()) {
        poolManager.addEVCacheEventListener(this);
    } else {
        poolManager.removeEVCacheEventListener(this);
        for(Cache<String, Integer> cache : cacheMap.values()) {
            cache.invalidateAll();
        }
    }
}
 
源代码10 项目: azeroth   文件: GuavaLevel1CacheProvider.java
public void remove(String cacheName, String key) {
    Cache<String, Object> cache = getCacheHolder(cacheName);
    if (cache != null) {
        cache.invalidateAll();
    }
}
 
源代码11 项目: azeroth   文件: GuavaLevel1CacheProvider.java
public void clearAll() {
    for (Cache<String, Object> cache : caches.values()) {
        cache.invalidateAll();
    }
}
 
源代码12 项目: dremio-oss   文件: S3FileSystem.java
private static final void invalidateCache(Cache<?, ?> cache) {
  cache.invalidateAll();
  cache.cleanUp();
}
 
源代码13 项目: jeesuite-libs   文件: GuavaLevel1CacheProvider.java
public void remove(String cacheName,String key){
	Cache<String, Object> cache = getCacheHolder(cacheName);
	if(cache != null){
		cache.invalidateAll();
	}
}
 
源代码14 项目: jeesuite-libs   文件: GuavaLevel1CacheProvider.java
public void clearAll(){
	for (Cache<String, Object> cache : caches.values()) {
		cache.invalidateAll();
	}
}