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:com.google.api.auth.CachingAuthTokenDecoder.java

@VisibleForTesting
CachingAuthTokenDecoder(AuthTokenDecoder authTokenDecoder, Ticker ticker) {
    this.authTokenCache = CacheBuilder.newBuilder().maximumSize(CACHE_CAPACITY)
            .expireAfterWrite(CACHE_EXPIRATION_IN_MINUTES, TimeUnit.MINUTES).ticker(ticker)
            .build(new DefaultCacheLoader(authTokenDecoder));
}

From source file:org.apache.aurora.scheduler.storage.db.MyBatisCacheImpl.java

private void initCache() {
    Preconditions.checkState(delegate == null);
    requireNonNull(size);/*  ww w.j  av a2  s  . com*/

    delegate = CacheBuilder.newBuilder().maximumSize(size).recordStats().softValues().build();
    initStats();
}

From source file:org.janusgraph.graphdb.database.RelationQueryCache.java

public RelationQueryCache(EdgeSerializer edgeSerializer, int capacity) {
    this.edgeSerializer = edgeSerializer;
    this.cache = CacheBuilder.newBuilder().maximumSize(capacity * 3 / 2).initialCapacity(capacity)
            .concurrencyLevel(2).build();
    relationTypes = new EnumMap<RelationCategory, SliceQuery>(RelationCategory.class);
    for (RelationCategory rt : RelationCategory.values()) {
        relationTypes.put(rt, edgeSerializer.getQuery(rt, false));
    }/*from ww  w. jav a2  s  .c  o m*/
}

From source file:net.sf.derquinsej.stats.TimingMapImpl.java

/**
 * Constructor.//from  www .  j a va  2 s  .c o  m
 * @param unit Time unit to use.
 */
TimingMapImpl(TimeUnit unit) {
    this.cache = CacheBuilder.newBuilder()
            .build(CacheLoader.from(compose(Timings.atomicCreator(), constant(unit))));
    this.view = unmodifiableMap(transformValues(cache.asMap(), atomicGetter()));
}

From source file:NotificationSystem.MessageComposer.java

public MessageComposer() {
    this.workflowCache = CacheBuilder.newBuilder().maximumSize(AlarmConfig.getInstance().getCacheSize())
            .expireAfterAccess(AlarmConfig.getInstance().getCachePersistanceTime(), TimeUnit.MINUTES)
            .build(new CacheLoader<String, WorkFlowInfo>() {
                public WorkFlowInfo load(String key) {
                    return retrieveWorkflowInfo(key);
                }/*from  w w w .j a  va  2  s .  co  m*/
            });

    this.userCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(10, TimeUnit.MINUTES)
            .build(new CacheLoader<String, UserData>() {
                public UserData load(String key) {
                    return retrieveUserInfo(key);
                }
            });

}

From source file:org.apache.hadoop.io.file.tfile.CacheManager.java

/**
 * (Re)Create the cache by limiting the maximum entries
 * @param concurrencyLevel//www  . ja v  a2s  .  com
 * @param initialCapacity
 * @param maximunSize
 * @return The cache.
 */
public static final Cache<String, BlockReader> createCache(int concurrencyLevel, int initialCapacity,
        int maximunSize) {
    CacheBuilder builder = CacheBuilder.newBuilder().concurrencyLevel(concurrencyLevel)
            .initialCapacity(initialCapacity).maximumSize(maximunSize);

    return buildCache(builder);
}

From source file:com.carrotgarden.log4j.aws.sns.EvaluatorThrottler.java

protected void ensureCache() {

    eventCache = CacheBuilder.newBuilder().expireAfterWrite(period, timeUnit).build();

}

From source file:springfox.documentation.spring.web.scanners.CachingOperationReader.java

@Autowired
public CachingOperationReader(@Qualifier("default") final OperationReader delegate) {
    cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(24, TimeUnit.HOURS)
            .build(new CacheLoader<Equivalence.Wrapper<RequestMappingContext>, List<Operation>>() {
                public List<Operation> load(Equivalence.Wrapper<RequestMappingContext> key) {
                    return delegate.read(key.get());
                }//from   w ww  .ja v a  2s  .co  m
            });
}

From source file:com.facebook.presto.chicago.ChicagoClientManager.java

@Inject
ChicagoClientManager(ChicagoConnectorConfig chicagoConnectorConfig) throws Exception {
    this.chicagoConnectorConfig = requireNonNull(chicagoConnectorConfig, "chicagoConfig is null");
    this.chicagoClientCache = CacheBuilder.newBuilder()
            .build(new ChicagoClientLoader(chicagoConnectorConfig.getZkString()));
}

From source file:com.yahoo.sshd.server.filesystem.AFClientCache.java

public AFClientCache(final ArtifactoryInformation inAfInfo, final ArtifactoryClientFactory inClientFactory) {
    this.clientFactory = inClientFactory;
    this.afInfo = inAfInfo;
    LOGGER.info("Setting up cache for Artifactory Client with max size " + CLIENT_CACHE_SIZE);
    this.cache = CacheBuilder.newBuilder().maximumSize(CLIENT_CACHE_SIZE)
            .build(new CacheLoader<String, JFrogArtifactoryClientHelper>() {
                @Override//from w w  w  .ja  v a 2 s. c  o  m
                public JFrogArtifactoryClientHelper load(final String repositoryName) {
                    // no checked exception
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Creating new Artifactory Client for repository " + repositoryName);
                    }
                    return clientFactory.createJFrogClientHelper(afInfo, repositoryName);
                }
            });
}