Example usage for com.google.common.cache Cache putAll

List of usage examples for com.google.common.cache Cache putAll

Introduction

In this page you can find the example usage for com.google.common.cache Cache putAll.

Prototype

void putAll(Map<? extends K, ? extends V> m);

Source Link

Document

Copies all of the mappings from the specified map to the cache.

Usage

From source file:org.apache.accumulo.core.clientImpl.BulkImport.java

private static Cache<String, Long> getPopulatedFileLenCache(Path dir, List<FileStatus> statuses) {
    Map<String, Long> fileLens = getFileLenMap(statuses);

    Map<String, Long> absFileLens = new HashMap<>();
    fileLens.forEach((k, v) -> {//from   w  w  w  . ja  va  2  s  . co m
        absFileLens.put(CachableBlockFile.pathToCacheId(new Path(dir, k)), v);
    });

    Cache<String, Long> fileLenCache = CacheBuilder.newBuilder().build();

    fileLenCache.putAll(absFileLens);

    return fileLenCache;
}

From source file:org.eclipse.milo.opcua.sdk.client.nodes.DefaultNodeCache.java

public synchronized void setExpireAfter(long duration, TimeUnit unit) {
    this.expireAfterNanos = unit.toNanos(duration);

    Cache<NodeId, Map<AttributeId, DataValue>> newCache = buildCache();

    newCache.putAll(cache.asMap());

    cache = newCache;//from   w w  w.j a  v a2s  .co m
}

From source file:org.eclipse.milo.opcua.sdk.client.nodes.DefaultNodeCache.java

public synchronized void setMaximumSize(long maximumSize) {
    this.maximumSize = maximumSize;

    Cache<NodeId, Map<AttributeId, DataValue>> newCache = buildCache();

    newCache.putAll(cache.asMap());

    cache = newCache;/*from  w  w w  .  jav  a2 s.  c om*/
}

From source file:org.codice.ddf.security.idp.server.CookieCache.java

/**
 * Set the expiration time for the cache. <br/><br/>
 * Note: This will also reset the expiration times of any items currently in the cache.
 *
 * @param expirationMinutes Value (in minutes) to set the cache expiration to.
 */// w  w w. ja va 2  s. c o m
public synchronized void setExpirationTime(int expirationMinutes) {
    if (expirationMinutes != currentExpiration) {
        LOGGER.debug(
                "New expiration value passed in. Changing cache to expire every {} minutes instead of every {}.",
                expirationMinutes, currentExpiration);
        Cache<String, Element> tmpCache = CacheBuilder.newBuilder()
                .expireAfterWrite(expirationMinutes, TimeUnit.MINUTES)
                .removalListener(new RemovalListenerLogger()).build();
        tmpCache.putAll(cache.asMap());
        LOGGER.debug("All cache items updated to expire after {} minutes.", expirationMinutes);
        cache = tmpCache;
        currentExpiration = expirationMinutes;
    } else {
        LOGGER.debug("Incoming time of {} matches current expiration time. Not updating cache.",
                expirationMinutes);
    }
}

From source file:org.codice.ddf.security.idp.cache.CookieCache.java

/**
 * Set the expiration time for the cache. <br/><br/>
 * Note: This will also reset the expiration times of any items currently in the cache.
 *
 * @param expirationMinutes Value (in minutes) to set the cache expiration to.
 *///from  w w w .  j av a 2s  .c  o m
public synchronized void setExpirationTime(int expirationMinutes) {
    if (expirationMinutes != currentExpiration) {
        LOGGER.debug(
                "New expiration value passed in. Changing cache to expire every {} minutes instead of every {}.",
                expirationMinutes, currentExpiration);
        Cache<String, DataWrapper> tmpCache = CacheBuilder.newBuilder()
                .expireAfterWrite(expirationMinutes, TimeUnit.MINUTES)
                .removalListener(new RemovalListenerLogger()).build();
        tmpCache.putAll(cache.asMap());
        LOGGER.debug("All cache items updated to expire after {} minutes.", expirationMinutes);
        cache = tmpCache;
        currentExpiration = expirationMinutes;
    } else {
        LOGGER.debug("Incoming time of {} matches current expiration time. Not updating cache.",
                expirationMinutes);
    }
}

From source file:org.mycore.common.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.//ww w .  j a  v a2s . c  o  m
 * 
 * @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();
}