本文整理汇总了Java中com.google.common.cache.CacheBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java CacheBuilder.build方法的具体用法?Java CacheBuilder.build怎么用?Java CacheBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.cache.CacheBuilder
的用法示例。
在下文中一共展示了CacheBuilder.build方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cacheManager
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
@Bean
public CacheManager cacheManager() {
log.debug("Creating Guava cache manager");
CacheBuilder<Object, Object> thirtyMinuteBuilder = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).recordStats();
CacheBuilder<Object, Object> oneHourBuilder = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).recordStats();
CacheBuilder<Object, Object> threeHoursBuilder = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.HOURS).recordStats();
Map<String, CacheBuilder<Object, Object>> builderMap = new LinkedHashMap<>();
builderMap.put("schedule", oneHourBuilder);
builderMap.put("team", threeHoursBuilder);
builderMap.put("roster", threeHoursBuilder);
builderMap.put("results", thirtyMinuteBuilder);
builderMap.put("legacyPlayer", threeHoursBuilder);
builderMap.put("player", threeHoursBuilder);
builderMap.put("banList", threeHoursBuilder);
builderMap.put("transactions", thirtyMinuteBuilder);
builderMap.put("overwatch", threeHoursBuilder);
GuavaCacheManager guavaCacheManager = new GuavaCacheManager() {
@Override
protected com.google.common.cache.Cache<Object, Object> createNativeGuavaCache(String name) {
CacheBuilder<Object, Object> builder = builderMap.get(name);
if (builder != null) {
log.debug("Creating cache for {}: {}", name, builder.toString());
return builder.build();
}
log.debug("Creating fallback cache for {}", name);
return super.createNativeGuavaCache(name);
}
};
guavaCacheManager.setCacheBuilder(thirtyMinuteBuilder);
return guavaCacheManager;
}
示例2: BaseProcessingUnit
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
/**
* Creates a new processing unit.
*
* @param name name.
* @param engine the engine.
* @param inQueue input queue.
* @param outQueue output queue.
*/
public BaseProcessingUnit(String name, Engine engine, EventQueue inQueue, EventQueue outQueue) {
super(name, engine);
this.inQueue = inQueue;
this.outQueue = outQueue;
long cacheExpireTime = engine.getDefaultParameters().getProcessingUnitEventProcessorCacheExpireTime();
if (cacheExpireTime >= 0) {
// Turn on the cache.
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
if (cacheExpireTime > 0) {
builder.expireAfterAccess(cacheExpireTime, TimeUnit.MILLISECONDS);
}
eventNameProcessorsCache = builder.build(new CacheLoader<String, Set<AtomicReference<T>>>() {
@Override
public Set<AtomicReference<T>> load(String eventName) throws Exception {
return resolveEventProcessors(eventName);
}
});
}
}
示例3: CachedScriptClassInstancePovider
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
public CachedScriptClassInstancePovider(Engine engine, Function<String, S> createScriptFunction, String format,
BiFunction<S, Class<T>, T> createInstanceFunction) {
this.createScriptFunction = createScriptFunction;
this.format = format;
this.createInstanceFunction = createInstanceFunction;
long cacheExpireTime = engine.getDefaultParameters().getScriptClassInstancePoviderCacheExpireTime();
if (cacheExpireTime >= 0) {
// Turn on the cache.
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
if (cacheExpireTime > 0) {
builder.expireAfterAccess(cacheExpireTime, TimeUnit.MILLISECONDS);
}
cache = builder.build(new CacheLoader<String, S>() {
@Override
public S load(String className) throws Exception {
return createScript(className);
}
});
}
}
示例4: MessageSlicer
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
private MessageSlicer(final Builder builder) {
this.fileBackedStreamFactory = builder.fileBackedStreamFactory;
this.messageSliceSize = builder.messageSliceSize;
this.maxSlicingTries = builder.maxSlicingTries;
id = SLICER_ID_COUNTER.getAndIncrement();
this.logContext = builder.logContext + "_slicer-id-" + id;
CacheBuilder<Identifier, SlicedMessageState<ActorRef>> cacheBuilder =
CacheBuilder.newBuilder().removalListener(notification -> stateRemoved(notification));
if (builder.expireStateAfterInactivityDuration > 0) {
cacheBuilder = cacheBuilder.expireAfterAccess(builder.expireStateAfterInactivityDuration,
builder.expireStateAfterInactivityUnit);
}
stateCache = cacheBuilder.build();
}
示例5: InMemoryTaskArtifactCache
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
private InMemoryTaskArtifactCache(CacheCapSizer cacheCapSizer) {
this.cacheCapSizer = cacheCapSizer;
final CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder()
.maximumSize(cacheCapSizer.getNumberOfCaches() * 2);
this.cache = cacheBuilder //X2 to factor in a child build (for example buildSrc)
.build();
}
示例6: DefaultSimpleCache
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
/**
* Construct a cache using the specified capacity and name.
*
* @param maxItems The cache capacity. 0 = use {@link #DEFAULT_CAPACITY}
* @param useMaxItems Whether the maxItems value should be applied as a size-cap for the cache.
* @param cacheName An arbitrary cache name.
*/
@SuppressWarnings("unchecked")
public DefaultSimpleCache(int maxItems, boolean useMaxItems, int ttlSecs, int maxIdleSecs, String cacheName)
{
if (maxItems == 0)
{
maxItems = DEFAULT_CAPACITY;
}
else if (maxItems < 0)
{
throw new IllegalArgumentException("maxItems may not be negative, but was " + maxItems);
}
this.maxItems = maxItems;
this.useMaxItems = useMaxItems;
this.ttlSecs = ttlSecs;
this.maxIdleSecs = maxIdleSecs;
setBeanName(cacheName);
// The map will have a bounded size determined by the maxItems member variable.
@SuppressWarnings("rawtypes")
CacheBuilder builder = CacheBuilder.newBuilder();
if (useMaxItems)
{
builder.maximumSize(maxItems);
}
if (ttlSecs > 0)
{
builder.expireAfterWrite(ttlSecs, TimeUnit.SECONDS);
}
if (maxIdleSecs > 0)
{
builder.expireAfterAccess(maxIdleSecs, TimeUnit.SECONDS);
}
builder.concurrencyLevel(32);
cache = (Cache<K, AbstractMap.SimpleImmutableEntry<K, V>>) builder.build();
}
示例7: newCache
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
static <K, V, E extends Exception> LoadingCache<K, V> newCache(CacheBuilder<K, V> builder, ThrowingFunction<K, V, E> loader) {
return builder.build(new CacheLoader<K, V>() {
@Override
public V load(K key) throws E {
return loader.applyThrows(key);
}
});
}
示例8: buildCache
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
private void buildCache() {
long sizeInBytes = MemorySizeValue.parseBytesSizeValueOrHeapRatio(size, INDICES_CACHE_QUERY_SIZE).bytes();
CacheBuilder<Key, Value> cacheBuilder = CacheBuilder.newBuilder()
.maximumWeight(sizeInBytes).weigher(new QueryCacheWeigher()).removalListener(this);
cacheBuilder.concurrencyLevel(concurrencyLevel);
if (expire != null) {
cacheBuilder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS);
}
cache = cacheBuilder.build();
}
示例9: SetCacheImpl
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
/**
* @param maxSize the maximum number of entries that the cache can hold
* @param expireDuration the length of time after an entry is created that it should be
* automatically removed
* @param expireUnit the unit that {@code duration} is expressed in
* @param concurrencyLevel guides the allowed concurrency among update operations. Used as a
* hint for internal sizing. Refer to Guava CacheBuilder for specific
* details.
*/
public SetCacheImpl(int maxSize, long expireDuration, TimeUnit expireUnit, int concurrencyLevel) {
CacheBuilder builder = CacheBuilder.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(expireDuration, expireUnit);
if (concurrencyLevel > 0) {
builder = builder.concurrencyLevel(concurrencyLevel);
}
this.cache = builder.build();
}
示例10: DatabaseCache
import com.google.common.cache.CacheBuilder; //导入方法依赖的package包/类
protected DatabaseCache(DatabaseCollection<K, V> collection, CacheBuilder<K, V> builder) {
this.databaseCollection = collection;
this.wrapped = builder.build(getLoader());
this.load();
}