Example usage for com.google.common.base Suppliers memoizeWithExpiration

List of usage examples for com.google.common.base Suppliers memoizeWithExpiration

Introduction

In this page you can find the example usage for com.google.common.base Suppliers memoizeWithExpiration.

Prototype

public static <T> Supplier<T> memoizeWithExpiration(Supplier<T> delegate, long duration, TimeUnit unit) 

Source Link

Document

Returns a supplier that caches the instance supplied by the delegate and removes the cached value after the specified time has passed.

Usage

From source file:com.palantir.atlasdb.cleaner.ImmutableTimestampSupplier.java

public static Supplier<Long> createMemoizedWithExpiration(RemoteLockService lockService,
        TimestampService timestampService, LockClient lockClient) {
    return Suppliers.memoizeWithExpiration(
            new ImmutableTimestampSupplier(lockService, timestampService, lockClient), RELOAD_INTERVAL_MILLIS,
            TimeUnit.MILLISECONDS);
}

From source file:com.google.api.config.ServiceConfigFetcher.java

@VisibleForTesting
ServiceConfigFetcher(Supplier<Service> supplier) {
    this.serviceSupplier = Suppliers.memoizeWithExpiration(supplier, 10, TimeUnit.MINUTES);
}

From source file:co.cask.cdap.cli.completer.StringsCompleter.java

public StringsCompleter(Supplier<Collection<String>> strings) {
    checkNotNull(strings);//from www .j av a  2 s.  c om
    this.strings = Suppliers.memoizeWithExpiration(strings, 5000, TimeUnit.MILLISECONDS);
}

From source file:io.crate.expression.reference.sys.shard.ShardSizeExpression.java

public ShardSizeExpression(final IndexShard indexShard) {
    sizeSupplier = Suppliers.memoizeWithExpiration(new Supplier<Long>() {
        @Override/*from  ww w  . j av  a2 s  .  c  o m*/
        public Long get() {
            return indexShard.storeStats().getSizeInBytes();
        }
    }, 10, TimeUnit.SECONDS);
}

From source file:org.graylog.plugins.usagestatistics.UsageStatsNodeService.java

@VisibleForTesting
UsageStatsNodeService(Supplier<NodeDataSet> nodeDataSetSupplier, Duration cacheTimeout) {
    this.cachedDataSet = Suppliers.memoizeWithExpiration(nodeDataSetSupplier, cacheTimeout.getQuantity(),
            cacheTimeout.getUnit());/*from   www . j  av  a 2s.  c  o  m*/
}

From source file:org.graylog.plugins.usagestatistics.UsageStatsClusterService.java

@VisibleForTesting
UsageStatsClusterService(Supplier<ClusterDataSet> clusterDataSetSupplier, Duration cacheTimeout) {
    this.cachedDataSet = Suppliers.memoizeWithExpiration(clusterDataSetSupplier, cacheTimeout.getQuantity(),
            cacheTimeout.getUnit());/*from   w  w w  .  j a  va 2s  . co  m*/
}

From source file:io.crate.operation.reference.sys.shard.ShardSizeExpression.java

@Inject
public ShardSizeExpression(final IndexShard indexShard) {
    sizeSupplier = Suppliers.memoizeWithExpiration(new Supplier<Long>() {
        @Override//  w w w. ja v a2s .c  om
        public Long get() {
            return indexShard.storeStats().getSizeInBytes();
        }
    }, 10, TimeUnit.SECONDS);
}

From source file:io.crate.operation.reference.sys.shard.blob.BlobShardSizeExpression.java

@Inject
public BlobShardSizeExpression(final BlobShard blobShard) {
    totalUsageSupplier = Suppliers.memoizeWithExpiration(new Supplier<Long>() {
        @Override//from   www  .  ja va  2  s  .  c  o  m
        public Long get() {
            return blobShard.blobStats().totalUsage();
        }
    }, 10, TimeUnit.SECONDS);
}

From source file:de.cosmocode.commons.base.ExpiringThreadLocalMemoizingSupplier.java

public ExpiringThreadLocalMemoizingSupplier(final Supplier<T> supplier, final long duration,
        final TimeUnit unit) {

    this.supplier = Preconditions.checkNotNull(supplier, "Supplier");
    this.duration = duration;
    this.unit = Preconditions.checkNotNull(unit, "Unit");

    this.local = new ThreadLocal<Supplier<T>>() {

        @Override//from ww w .j a  v a  2s  . c om
        protected Supplier<T> initialValue() {
            return Suppliers.memoizeWithExpiration(supplier, duration, unit);
        }

    };
}

From source file:com.netflix.servo.monitor.MonitoredCache.java

MonitoredCache(final Cache<?, ?> cache) {
    final Supplier<CacheStats> supplier = new Supplier<CacheStats>() {
        public CacheStats get() {
            return cache.stats();
        }/*from w  ww  .  j  av a2  s  . co m*/
    };
    statsSupplier = Suppliers.memoizeWithExpiration(supplier, CACHE_TIME, TimeUnit.SECONDS);
}