本文整理了Java中com.github.benmanes.caffeine.cache.Caffeine.initialCapacity()
方法的一些代码示例,展示了Caffeine.initialCapacity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Caffeine.initialCapacity()
方法的具体详情如下:
包路径:com.github.benmanes.caffeine.cache.Caffeine
类名称:Caffeine
方法名:initialCapacity
[英]Sets the minimum total size for the internal data structures. Providing a large enough estimate at construction time avoids the need for expensive resizing operations later, but setting this value unnecessarily high wastes memory.
[中]设置内部数据结构的最小总大小。在构建时提供足够大的估计值可以避免以后需要昂贵的调整大小操作,但设置此值会不必要地浪费内存。
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void initialCapacity_twice() {
Caffeine.newBuilder().initialCapacity(1).initialCapacity(1);
}
代码示例来源:origin: ben-manes/caffeine
@Test
public void initialCapacity_large() {
// don't build! just check that it configures
Caffeine<?, ?> builder = Caffeine.newBuilder().initialCapacity(Integer.MAX_VALUE);
assertThat(builder.initialCapacity, is(Integer.MAX_VALUE));
}
代码示例来源:origin: ben-manes/caffeine
public void testInitialCapacity_setTwice() {
Caffeine<Object, Object> builder = Caffeine.newBuilder().initialCapacity(16);
try {
// even to the same value is not allowed
builder.initialCapacity(16);
fail();
} catch (IllegalStateException expected) {}
}
代码示例来源:origin: ben-manes/caffeine
public void testInitialCapacity_large() {
Caffeine.newBuilder().initialCapacity(Integer.MAX_VALUE);
// that the builder didn't blow up is enough;
// don't actually create this monster!
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalArgumentException.class)
public void initialCapacity_negative() {
Caffeine.newBuilder().initialCapacity(-1);
}
代码示例来源:origin: ben-manes/caffeine
@Test
public void initialCapacity_small() {
// can't check, so just assert that it builds
Caffeine<?, ?> builder = Caffeine.newBuilder().initialCapacity(0);
assertThat(builder.initialCapacity, is(0));
builder.build();
}
代码示例来源:origin: ben-manes/caffeine
public void testInitialCapacity_negative() {
Caffeine<Object, Object> builder = Caffeine.newBuilder();
try {
builder.initialCapacity(-1);
fail();
} catch (IllegalArgumentException expected) {}
}
代码示例来源:origin: ben-manes/caffeine
@Test
public void configured() {
Caffeine<Object, Object> configured = Caffeine.newBuilder()
.initialCapacity(1).weakKeys()
.expireAfterAccess(1, TimeUnit.SECONDS).expireAfterWrite(1, TimeUnit.SECONDS)
.removalListener((k, v, c) -> {}).recordStats();
assertThat(configured.build(), is(not(nullValue())));
assertThat(configured.buildAsync(), is(not(nullValue())));
assertThat(configured.build(loader), is(not(nullValue())));
assertThat(configured.buildAsync(loader), is(not(nullValue())));
assertThat(configured.refreshAfterWrite(1, TimeUnit.SECONDS).toString(),
is(not(Caffeine.newBuilder().toString())));
assertThat(Caffeine.newBuilder().maximumSize(1).toString(),
is(not(Caffeine.newBuilder().maximumWeight(1).toString())));
}
代码示例来源:origin: ben-manes/caffeine
public void testSizeConstraint() {
final Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.executor(MoreExecutors.directExecutor())
.initialCapacity(100)
.maximumSize(4));
// Enforce full initialization of internal structures
for (int i = 0; i < 4; i++) {
cache.put(i, i);
}
cache.invalidateAll();
cache.put(1, 10);
cache.put(2, 20);
cache.put(3, 30);
cache.put(4, 40);
cache.put(5, 50);
assertEquals(null, cache.getIfPresent(10));
// Order required to remove dependence on access order / write order constraint.
assertEquals(Integer.valueOf(10), cache.getIfPresent(1));
assertEquals(Integer.valueOf(20), cache.getIfPresent(2));
assertEquals(Integer.valueOf(30), cache.getIfPresent(3));
assertEquals(Integer.valueOf(50), cache.getIfPresent(5));
cache.put(1, 10);
assertEquals(Integer.valueOf(10), cache.getIfPresent(1));
assertEquals(Integer.valueOf(20), cache.getIfPresent(2));
assertEquals(Integer.valueOf(30), cache.getIfPresent(3));
assertEquals(Integer.valueOf(50), cache.getIfPresent(5));
assertEquals(null, cache.getIfPresent(4));
}
代码示例来源:origin: ben-manes/caffeine
public CaffeinePolicy(Config config) {
policyStats = new PolicyStats("product.Caffeine");
BasicSettings settings = new BasicSettings(config);
maximumSize = settings.maximumSize();
cache = Caffeine.newBuilder()
.initialCapacity(maximumSize)
.maximumSize(maximumSize)
.executor(Runnable::run)
.build();
}
代码示例来源:origin: ben-manes/caffeine
.executor(MoreExecutors.directExecutor())
.removalListener(countingListener)
.initialCapacity(100)
.ticker(fakeTicker::read)
.maximumSize(2));
代码示例来源:origin: ben-manes/caffeine
.initialCapacity(1000)
.executor(MoreExecutors.directExecutor()), computeFunction);
ConcurrentMap<String,String> map = cache.asMap();
代码示例来源:origin: ben-manes/caffeine
Caffeine<Object, Object> builder = Caffeine.newBuilder();
if (initialCapacity != UNSET_INT) {
builder.initialCapacity(initialCapacity);
代码示例来源:origin: ben-manes/caffeine
public void testCaffeineFrom_string() {
Caffeine<?, ?> fromString = Caffeine.from(
"initialCapacity=10,maximumSize=20,weakKeys,weakValues,expireAfterAccess=10m");
Caffeine<?, ?> expected = Caffeine.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.weakKeys()
.weakValues()
.expireAfterAccess(10L, TimeUnit.MINUTES);
assertCaffeineEquivalence(expected, fromString);
}
代码示例来源:origin: ben-manes/caffeine
builder.initialCapacity(initialCapacity);
代码示例来源:origin: ben-manes/caffeine
public void testParse_initialCapacity() {
CaffeineSpec spec = parse("initialCapacity=10");
assertEquals(10, spec.initialCapacity);
assertEquals(spec.maximumSize, UNSET_INT);
assertEquals(spec.maximumWeight, UNSET_INT);
assertNull(spec.keyStrength);
assertNull(spec.valueStrength);
assertNull(spec.expireAfterWriteTimeUnit);
assertNull(spec.expireAfterAccessTimeUnit);
assertNull(spec.refreshAfterWriteTimeUnit);
assertCaffeineEquivalence(
Caffeine.newBuilder().initialCapacity(10), Caffeine.from(spec));
}
代码示例来源:origin: ben-manes/caffeine
public void testParse_whitespaceAllowed() {
CaffeineSpec spec = parse(" initialCapacity=10,\nmaximumSize=20,\t\r"
+ "weakKeys \t ,softValues \n , \r expireAfterWrite \t = 15s\n\n");
assertEquals(10, spec.initialCapacity);
assertEquals(20, spec.maximumSize);
assertEquals(spec.maximumWeight, UNSET_INT);
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.SOFT, spec.valueStrength);
assertEquals(TimeUnit.SECONDS, spec.expireAfterWriteTimeUnit);
assertEquals(15L, spec.expireAfterWriteDuration);
assertNull(spec.expireAfterAccessTimeUnit);
Caffeine<?, ?> expected = Caffeine.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.weakKeys()
.softValues()
.expireAfterWrite(15L, TimeUnit.SECONDS);
assertCaffeineEquivalence(expected, Caffeine.from(spec));
}
代码示例来源:origin: ben-manes/caffeine
public void testParse_multipleKeys() {
CaffeineSpec spec = parse("initialCapacity=10,maximumSize=20,"
+ "weakKeys,weakValues,expireAfterAccess=10m,expireAfterWrite=1h");
assertEquals(10, spec.initialCapacity);
assertEquals(20, spec.maximumSize);
assertEquals(spec.maximumWeight, UNSET_INT);
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.WEAK, spec.valueStrength);
assertEquals(TimeUnit.HOURS, spec.expireAfterWriteTimeUnit);
assertEquals(TimeUnit.MINUTES, spec.expireAfterAccessTimeUnit);
assertEquals(1L, spec.expireAfterWriteDuration);
assertEquals(10L, spec.expireAfterAccessDuration);
Caffeine<?, ?> expected = Caffeine.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.weakKeys()
.weakValues()
.expireAfterAccess(10L, TimeUnit.MINUTES)
.expireAfterWrite(1L, TimeUnit.HOURS);
assertCaffeineEquivalence(expected, Caffeine.from(spec));
}
代码示例来源:origin: Nepxion/Discovery
public PluginCache() {
loadingCache = Caffeine.newBuilder()
.expireAfterWrite(365 * 100, TimeUnit.DAYS)
.initialCapacity(10)
.maximumSize(100)
.recordStats()
.build(new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
return StringUtils.EMPTY;
}
});
}
代码示例来源:origin: ben-manes/caffeine
builder.initialCapacity(context.initialCapacity.size());
内容来源于网络,如有侵权,请联系作者删除!