Example usage for com.google.common.cache LoadingCache refresh

List of usage examples for com.google.common.cache LoadingCache refresh

Introduction

In this page you can find the example usage for com.google.common.cache LoadingCache refresh.

Prototype

void refresh(K key);

Source Link

Document

Loads a new value for key key , possibly asynchronously.

Usage

From source file:rickbw.incubator.cache.LoadingMultiCache.java

@Override
public void refresh(final K key) {
    final LoadingCache<K, V> cache = getCacheNonNull(key);
    cache.refresh(key);
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.dns.ZoneManager.java

private static Runnable getMaintenanceRunnable(final LoadingCache<ZoneKey, Zone> cache,
        final ZoneCacheType type, final int refreshInterval) {
    return new Runnable() {
        public void run() {
            cache.cleanUp();//from   w w  w  . j av a  2 s . c  o m

            for (final ZoneKey zoneKey : cache.asMap().keySet()) {
                try {
                    if (signatureManager.needsRefresh(type, zoneKey, refreshInterval)) {
                        cache.refresh(zoneKey);
                    }
                } catch (RuntimeException ex) {
                    LOGGER.fatal("RuntimeException caught on " + zoneKey.getClass().getSimpleName() + " for "
                            + zoneKey.getName(), ex);
                }
            }
        }
    };
}

From source file:ca.exprofesso.guava.jcache.GuavaCache.java

@Override
public void loadAll(final Set<? extends K> keys, final boolean replaceExistingValues,
        final CompletionListener cl) {
    checkState();//  w  w w  .java 2  s . c  o  m

    if (keys == null || cl == null) {
        throw new NullPointerException();
    }

    ExecutorService executorService = Executors.newSingleThreadExecutor();

    executorService.submit(new Runnable() {
        @Override
        public void run() {
            try {
                if (cache instanceof LoadingCache) {
                    LoadingCache<K, V> loadingCache = (LoadingCache<K, V>) cache;

                    for (K key : keys) {
                        if (!view.containsKey(key)) {
                            loadingCache.get(key);
                        } else if (replaceExistingValues) {
                            loadingCache.refresh(key);
                        }
                    }
                }
            } catch (ExecutionException e) {
                cl.onException(e);
            } finally {
                cl.onCompletion();
            }
        }
    });
}