Example usage for com.google.common.cache CacheBuilder newBuilder

List of usage examples for com.google.common.cache CacheBuilder newBuilder

Introduction

In this page you can find the example usage for com.google.common.cache CacheBuilder newBuilder.

Prototype

public static CacheBuilder<Object, Object> newBuilder() 

Source Link

Document

Constructs a new CacheBuilder instance with default settings, including strong keys, strong values, and no automatic eviction of any kind.

Usage

From source file:org.dishevelled.processing.executor.Executor.java

public Executor(final PApplet applet, final int threadPoolSize) {
    checkNotNull(applet, "applet must not be null");
    this.applet = applet;
    calls = CacheBuilder.newBuilder().build(new ReflectiveMethodCall());
    scheduledExecutorService = Executors.newScheduledThreadPool(threadPoolSize);
}

From source file:com.analog.lyric.dimple.jsproxy.JSDomainFactory.java

/**
 * For tests purposes only.
 */
@SuppressWarnings("null")
@Internal
public JSDomainFactory() {
    _applet = null;
    _proxyCache = CacheBuilder.newBuilder().build();
}

From source file:io.druid.java.util.http.client.pool.ResourcePool.java

public ResourcePool(final ResourceFactory<K, V> factory, final ResourcePoolConfig config) {
    this.pool = CacheBuilder.newBuilder().build(new CacheLoader<K, ImmediateCreationResourceHolder<K, V>>() {
        @Override//from  w w  w . j av a  2s .  co m
        public ImmediateCreationResourceHolder<K, V> load(K input) {
            return new ImmediateCreationResourceHolder<K, V>(config.getMaxPerKey(),
                    config.getUnusedConnectionTimeoutMillis(), input, factory);
        }
    });
}

From source file:org.eclipse.emf.compare.match.eobject.ByTypeIndex.java

/**
 * Create a new instance using the given {@link DistanceFunction} to instantiate delegate indexes on
 * demand./*from  w w  w .  j a v a 2 s.  c o m*/
 * 
 * @param meter
 *            the function passed when instantiating delegate indexes.
 */
public ByTypeIndex(ProximityEObjectMatcher.DistanceFunction meter) {
    this.meter = meter;
    this.allIndexes = CacheBuilder.newBuilder().build(CacheLoader.from(new Function<String, EObjectIndex>() {
        public EObjectIndex apply(String input) {
            return new ProximityIndex(ByTypeIndex.this.meter);
        }
    }));
}

From source file:org.alkemy.NodeCache.java

public NodeCache(AlkemyParser parser, long maxSize) {
    this.parser = parser;
    this.cache = CacheBuilder.newBuilder()//
            .maximumWeight(maxSize)//
            .weigher((k, v) -> (int) Agents.getObjectSize(k))//
            .expireAfterAccess(60, TimeUnit.MINUTES)//
            .build(new CacheLoader<Class<?>, Node<AlkemyElement>>() {
                @Override/*from w ww . ja va  2  s.  c o  m*/
                public Node<AlkemyElement> load(Class<?> key) throws AlkemyException {
                    return _create(key);
                }
            });
}

From source file:com.facebook.buck.rules.keys.InputCountingRuleKeyBuilderFactory.java

public InputCountingRuleKeyBuilderFactory(int seed, FileHashLoader hashLoader,
        SourcePathResolver pathResolver) {
    super(seed);// w  ww  . ja v a2 s . c  o m
    this.resultCache = CacheBuilder.newBuilder().weakKeys()
            .build(new CacheLoader<RuleKeyAppendable, InputCountingRuleKeyBuilderFactory.Result>() {
                @Override
                public InputCountingRuleKeyBuilderFactory.Result load(@Nonnull RuleKeyAppendable appendable)
                        throws Exception {
                    RuleKeyBuilder<InputCountingRuleKeyBuilderFactory.Result> subKeyBuilder = newBuilder();
                    appendable.appendToRuleKey(subKeyBuilder);
                    return subKeyBuilder.build();
                }
            });
    this.hashLoader = hashLoader;
    this.pathResolver = pathResolver;
}

From source file:org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule.java

@Provides
@Singleton//from  w  ww . j av  a2  s  . c  om
protected LoadingCache<String, URI> cdnContainer(final CloudFilesClient client) {
    return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS)
            .build(new CacheLoader<String, URI>() {
                @Override
                public URI load(String container) {
                    ContainerCDNMetadata md = client.getCDNMetadata(container);
                    return md != null ? md.getCDNUri() : null;
                }

                @Override
                public String toString() {
                    return "getCDNMetadata()";
                }
            });
}

From source file:co.cask.cdap.common.conf.ArtifactConfigReader.java

public ArtifactConfigReader() {
    this.gsonCache = CacheBuilder.newBuilder().build(new CacheLoader<Id.Namespace, Gson>() {
        @Override// w  w w  .j a v a2  s  .c  o m
        public Gson load(Id.Namespace namespace) throws Exception {
            return new GsonBuilder()
                    .registerTypeAdapter(ArtifactRange.class, new ArtifactRangeDeserializer(namespace))
                    .registerTypeAdapter(ArtifactConfig.class, new ArtifactConfigDeserializer())
                    .registerTypeAdapter(PluginClass.class, new PluginClassDeserializer()).create();
        }
    });
}

From source file:sockslib.server.manager.HashPasswordProtector.java

public HashPasswordProtector(HashAlgorithm algorithm, int hashTime) {
    this.algorithm = algorithm;
    this.hashTime = hashTime;
    cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(5, TimeUnit.MINUTES)
            .build(new CacheLoader<String, String>() {
                @Override// w w  w  .jav a2 s.  co m
                public String load(String key) throws Exception {
                    return encryptNow(key);
                }
            });
}

From source file:io.geobit.chain.providers.block.BlocksCache.java

public BlocksCache() {
    super();/*from   w  ww. j  a va 2s  .c om*/
    confirmedBlocks = new HashMap<Integer, Block>(); /* all the confirmed blocks could fit in HashMap */

    recentBlocks = CacheBuilder.newBuilder().maximumSize(100)
            .expireAfterWrite(5,
                    TimeUnit.MINUTES) /* expiring after five minutes, if recent, could be orphaned block */
            .build(new CacheLoader<Integer, Block>() {
                public Block load(Integer height) { /* never been called */
                    log("BlockAndTransactionDispatcher recent blocks cache. key " + height);
                    throw new RuntimeException(
                            "BlockAndTransactionDispatcher recent blocks cache address invalid");
                }
            });
}