List of usage examples for com.google.common.cache CacheBuilder from
@GwtIncompatible("To be supported") public static CacheBuilder<Object, Object> from(String spec)
From source file:com.google.javascript.jscomp.bundle.CachedTransformer.java
public CachedTransformer(Source.Transformer delegate, String spec) { this(delegate, CacheBuilder.from(spec)); }
From source file:zipkin.storage.cassandra.CompositeIndexer.java
CompositeIndexer(Session session, CacheBuilderSpec spec, int bucketCount, @Nullable Integer indexTtl) { this.sharedState = spec == null ? null : CacheBuilder.from(spec).<PartitionKeyToTraceId, Pair<Long>>build().asMap(); Indexer.Factory factory = new Indexer.Factory(session, indexTtl, sharedState); this.indexers = ImmutableSet.of(factory.create(new InsertTraceIdByServiceName(bucketCount)), factory.create(new InsertTraceIdBySpanName()), factory.create(new InsertTraceIdByAnnotation(bucketCount))); }
From source file:zipkin2.storage.cassandra.v1.CompositeIndexer.java
CompositeIndexer(CassandraStorage storage, CacheBuilderSpec spec, int indexTtl) { this.sharedState = CacheBuilder.from(spec).<PartitionKeyToTraceId, Pair>build().asMap(); Indexer.Factory factory = new Indexer.Factory(storage.session(), indexTtl, sharedState); ImmutableSet.Builder<Indexer> indexers = ImmutableSet.builder(); indexers.add(factory.create(new InsertTraceIdByServiceName(storage.bucketCount))); if (storage.metadata().hasRemoteService) { indexers.add(factory.create(new InsertTraceIdByRemoteServiceName())); }/*from w ww .j a v a 2 s . c om*/ indexers.add(factory.create(new InsertTraceIdBySpanName())); indexers.add(factory.create(new InsertTraceIdByAnnotation(storage.bucketCount))); this.indexers = indexers.build(); }
From source file:com.rhythm.louie.cache.GuavaLoadingCache.java
@SuppressWarnings("unchecked") public static <K, V> GuavaLoadingCache<K, V> fromSpec(String name, String spec, CacheLoader<K, V> loader) { return new GuavaLoadingCache(name, CacheBuilder.from(spec), loader); }
From source file:org.nickelproject.nickel.blobStore.CachingBlobStore.java
@Inject public CachingBlobStore(final BlobStore blobStore, final CacheBuilderSpec cacheBuilderSpec) { this.blobStore = blobStore; this.cache = CacheBuilder.from(cacheBuilderSpec).weigher(new Weigher<BlobRef, byte[]>() { @Override/*from ww w . j av a 2s.c om*/ public int weigh(final BlobRef key, final byte[] value) { return value.length; } }).build(new CacheLoader<BlobRef, byte[]>() { @Override public byte[] load(final BlobRef key) throws Exception { return blobStore.get(key); } }); }
From source file:org.arbeitspferde.friesian.ConfigurableMapMakerCache.java
public ConfigurableMapMakerCache(final CacheBuilderSpec specification) throws IllegalArgumentException { Preconditions.checkNotNull(specification, "specification may not be null."); Preconditions.checkArgument(!specification.toParsableString().isEmpty(), "specification may not be empty."); backingMap = CacheBuilder.from(specification).<Integer, T>build().asMap(); log.info(String.format("Created map with %s specification.", specification)); }
From source file:org.nickelproject.nickel.objectStore.CachingObjectStore.java
@Inject public CachingObjectStore(final BlobStore bStore, final CacheBuilderSpec cacheBuilderSpec) { this.blobStore = bStore; this.cache = CacheBuilder.from(cacheBuilderSpec).weigher(new Weigher<BlobRef, Pair<Integer, Object>>() { @Override/* w w w.ja v a 2s. c o m*/ public int weigh(final BlobRef key, final Pair<Integer, Object> value) { return value.getA(); } }).build(new CacheLoader<BlobRef, Pair<Integer, Object>>() { @Override public Pair<Integer, Object> load(final BlobRef key) throws Exception { final byte[] bytes = blobStore.get(key); if (bytes == null) { throw new RuntimeException("Unable to load for key: " + key); } else { return Pair.of(bytes.length, SerializationUtils.deserialize(bytes)); } } }); }
From source file:cherry.foundation.numbering.NumberingManagerImpl.java
@Override public void afterPropertiesSet() { definitionCache = CacheBuilder.from(cacheSpec).build(new CacheLoader<String, NumberingDefinition>() { @Override// ww w . j av a 2s. c o m public NumberingDefinition load(String key) { return numberingStore.getDefinition(key); } }); }
From source file:com.pinterest.teletraan.security.UserDataHelper.java
public UserDataHelper(String userDataUrl, String groupDataUrl, String tokenCacheSpec, TeletraanServiceContext context) { this.userDataUrl = userDataUrl; this.groupDataUrl = groupDataUrl; this.context = context; if (!StringUtils.isEmpty(tokenCacheSpec)) { tokenCache = CacheBuilder.from(tokenCacheSpec).build(new CacheLoader<String, UserSecurityContext>() { @Override//from ww w . j av a 2 s.c o m public UserSecurityContext load(String token) throws Exception { return loadOauthUserData(token); } }); } }
From source file:org.springmodules.cache.guava.GuavaCacheFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { if (StringUtils.hasText(this.spec)) { this.cache = new GuavaCache(this.name, CacheBuilder.from(spec), allowNullValues); } else {//from w w w.j av a2s . c om this.cache = new GuavaCache(this.name, allowNullValues); } }