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

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

Introduction

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

Prototype

void put(K key, V value);

Source Link

Document

Associates value with key in this cache.

Usage

From source file:org.eclipse.osee.jaxrs.client.internal.JaxRsClientRuntime.java

private static OAuthFactory newOAuthFactory() {
    return new OAuthFactory() {

        @Override//from   ww w.j a va 2  s  .  c  o m
        public OAuth2ClientRequestFilter newOAuthClientFilter(String username, String password, String clientId,
                String clientSecret, String authorizeUri, String tokenUri, String tokenValidationUri) {
            OwnerCredentials owner = newOwner(username, password);
            OAuthClientUtils.Consumer client = new OAuthClientUtils.Consumer(clientId, clientSecret);
            OAuth2Transport transport = new OAuth2Transport();
            OAuth2Flows flowManager = new OAuth2Flows(transport, owner, client, authorizeUri, tokenUri,
                    tokenValidationUri);
            OAuth2Serializer serializer = new OAuth2Serializer();
            return new OAuth2ClientRequestFilter(flowManager, serializer);
        }

        @Override
        public ClientAccessTokenCache newClientAccessTokenCache(int cacheMaxSize,
                long cacheEvictTimeoutMillis) {
            final Cache<URI, ClientAccessToken> cache = newCache(cacheMaxSize, cacheEvictTimeoutMillis);
            return new ClientAccessTokenCache() {

                @Override
                public ClientAccessToken get(URI key) {
                    return cache.getIfPresent(key);
                }

                @Override
                public void store(URI key, ClientAccessToken value) {
                    cache.put(key, value);
                }
            };
        }

    };
}

From source file:org.jclouds.rest.config.SyncToAsyncHttpInvocationModule.java

public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) {
    for (Invokable<?, ?> invoked : methods(sync)) {
        Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked));
        checkArgument(/*from  www .  j a  v  a  2 s  .  c o  m*/
                delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes())
                        || isCloseable(delegatedMethod),
                "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod);
        cache.put(invoked, delegatedMethod);
    }
}

From source file:net.minecraftforge.common.ForgeChunkManager.java

public static void putDormantChunk(long coords, Chunk chunk) {
    Cache<Long, Chunk> cache = dormantChunkCache.get(chunk.getWorld());
    if (cache != null) {
        cache.put(coords, chunk);
    }//from   w  ww .ja va2 s.  c  om
}

From source file:fr.inria.atlanmod.neo4emf.drivers.impl.ProxyManager.java

@Override
public void putToProxy(INeo4emfObject obj) {
    EClass eClass = obj.eClass();/* w  w  w. j  av  a2 s.  co m*/

    if (nodes2objects.containsKey(eClass)) {
        nodes2objects.get(eClass).put(obj.getNodeId(), obj);
    }
    // here need to check the super classes
    else {
        //         Cache<Long,INeo4emfObject> cache = CacheBuilder.newBuilder().softValues().build();
        Cache<Long, INeo4emfObject> cache = CacheBuilder.newBuilder().weakValues().build();
        cache.put(obj.getNodeId(), obj);
        nodes2objects.put(eClass, cache);
    }
}

From source file:org.geogit.di.caching.ObjectDatabaseGetCacheInterceptor.java

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    final ObjectId oid = (ObjectId) invocation.getArguments()[0];

    final Cache<ObjectId, RevObject> cache = cacheProvider.get().get();

    Object object = cache.getIfPresent(oid);
    if (object == null) {
        object = invocation.proceed();/* ww w .j  av  a 2  s. co  m*/
        if (isCacheable(object)) {
            cache.put(oid, (RevObject) object);
        }
    }
    return object;
}

From source file:com.reachcall.pretty.peering.RemoteSessionWatcher.java

@Override
public void onHeartbeat(Object remote) {
    if (remote instanceof Session) {
        try {/*w w w.j a v a2 s .c  om*/
            //TODO store configuration hashes and check the current actives.

            Session inc = (Session) remote;
            LOG.log(Level.INFO, "Got session {0} {1}", new Object[] { inc.host, inc.sessionToken });
            Cache<String, Session> hostcache = cache.get(inc.host, this.callable);

            if (inc.configuration != null) {
                hostcache.put(inc.sessionToken, inc);
            } else {
                Session old = hostcache.getIfPresent(inc.sessionToken);
                if (old != null) {
                    LOG.log(Level.FINER, "Hit on {0} session {1}", new Object[] { old.host, old.sessionToken });
                }
            }
        } catch (ExecutionException ex) {
            LOG.log(Level.SEVERE, "Exception dealing with remote session hit", ex);
        }
    }
}

From source file:com.heliosapm.easymq.cache.CacheService.java

/**
 * Stores a value to a named instance cache
 * @param poolKey The MQ instance pool key
 * @param cacheName The name of the cache to insert into
 * @param key The cache put key/*from  w w w  .  j  av a 2 s .  c  o m*/
 * @param value The cache put value
 */
public void put(final String poolKey, final String cacheName, final Object key, final Object value) {
    @SuppressWarnings("unchecked")
    final Cache<Object, Object> cache = (Cache<Object, Object>) getNamedInstanceCache(poolKey, cacheName);
    cache.put(key, value);
}

From source file:com.watchrabbit.executor.service.CacheServiceImpl.java

private <V> Callable<V> wrap(Callable<V> callable, Cache<String, Object> cache, String key) {
    return () -> {
        try {//from   ww  w  .  ja v  a  2 s .co  m
            V value = (V) cache.getIfPresent(key);
            if (value == null) {
                value = callable.call();
                if (value != null) {
                    cache.put(key, value);
                }
            }
            return value;
        } catch (ExecutionException ex) {
            LOGGER.debug("Error on cache loading", ex);
            throw ex;
        }
    };
}

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

@Override
public final void put(final K elementKey, final V value) {
    final Cache<K, V> cache = getCacheNonNull(elementKey);
    cache.put(elementKey, value);
}

From source file:tech.beshu.ror.acl.definitions.DefinitionsFactory.java

private <T> T getOrCreate(NamedSettings settings, Cache<String, T> cache, Supplier<T> creator) {
    T cached = cache.getIfPresent(settings.getName());
    if (cached != null)
        return cached;

    T created = creator.get();/* w  w  w  . j a va 2 s  .c  o m*/
    cache.put(settings.getName(), created);
    return created;
}