本文整理汇总了Java中com.google.common.cache.CacheBuilder.expireAfterWrite方法的典型用法代码示例。如果您正苦于以下问题:Java CacheBuilder.expireAfterWrite方法的具体用法?Java CacheBuilder.expireAfterWrite怎么用?Java CacheBuilder.expireAfterWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.cache.CacheBuilder
的用法示例。
在下文中一共展示了CacheBuilder.expireAfterWrite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}