com.github.benmanes.caffeine.cache.Caffeine.from()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中com.github.benmanes.caffeine.cache.Caffeine.from()方法的一些代码示例,展示了Caffeine.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Caffeine.from()方法的具体详情如下:
包路径:com.github.benmanes.caffeine.cache.Caffeine
类名称:Caffeine
方法名:from

Caffeine.from介绍

[英]Constructs a new Caffeine instance with the settings specified in spec.
[中]使用规范中指定的设置构造一个新实例。

代码示例

代码示例来源:origin: dropwizard/dropwizard

/**
 * Creates a new cached authenticator.
 *
 * @param metricRegistry the application's registry of metrics
 * @param authenticator  the underlying authenticator
 * @param cacheSpec      a {@link CaffeineSpec}
 */
public CachingAuthenticator(final MetricRegistry metricRegistry,
              final Authenticator<C, P> authenticator,
              final CaffeineSpec cacheSpec) {
  this(metricRegistry, authenticator, Caffeine.from(cacheSpec));
}

代码示例来源:origin: dropwizard/dropwizard

/**
 * Creates a new cached authorizer.
 *
 * @param metricRegistry the application's registry of metrics
 * @param authorizer     the underlying authorizer
 * @param cacheSpec      {@link CaffeineSpec}
 */
public CachingAuthorizer(
  final MetricRegistry metricRegistry,
  final Authorizer<P> authorizer,
  final CaffeineSpec cacheSpec) {
  this(metricRegistry, authorizer, Caffeine.from(cacheSpec));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the {@link CaffeineSpec} to use for building each individual
 * {@link CaffeineCache} instance.
 * @see #createNativeCaffeineCache
 * @see com.github.benmanes.caffeine.cache.Caffeine#from(CaffeineSpec)
 */
public void setCaffeineSpec(CaffeineSpec caffeineSpec) {
  doSetCaffeine(Caffeine.from(caffeineSpec));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the Caffeine cache specification String to use for building each
 * individual {@link CaffeineCache} instance. The given value needs to
 * comply with Caffeine's {@link CaffeineSpec} (see its javadoc).
 * @see #createNativeCaffeineCache
 * @see com.github.benmanes.caffeine.cache.Caffeine#from(String)
 */
public void setCacheSpecification(String cacheSpecification) {
  doSetCaffeine(Caffeine.from(cacheSpecification));
}

代码示例来源:origin: ben-manes/caffeine

@Test(expectedExceptions = NullPointerException.class)
public void fromSpec_null() {
 Caffeine.from((CaffeineSpec) null);
}

代码示例来源:origin: ben-manes/caffeine

@Test
public void fromString_lenientParsing() {
 Caffeine.from("maximumSize=100").weigher((k, v) -> 0).build();
}

代码示例来源:origin: ben-manes/caffeine

public void testMaximumSize_withoutWeigher() {
 Caffeine<Object, Object> builder = Caffeine.from(parse("maximumSize=9000"));
 builder.build(k -> null);
}

代码示例来源:origin: ben-manes/caffeine

public void testMaximumWeight_withoutWeigher() {
 Caffeine<Object, Object> builder = Caffeine.from(parse("maximumWeight=9000"));
 try {
  builder.build(k -> null);
  fail();
 } catch (IllegalStateException expected) {}
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_recordStats() {
 CaffeineSpec spec = parse("recordStats");
 assertTrue(spec.recordStats);
 assertCaffeineEquivalence(Caffeine.newBuilder().recordStats(), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_writeExpirationHours() {
 CaffeineSpec spec = parse("expireAfterWrite=150h");
 assertEquals(TimeUnit.HOURS, spec.expireAfterWriteTimeUnit);
 assertEquals(150L, spec.expireAfterWriteDuration);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().expireAfterWrite(150L, TimeUnit.HOURS), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_accessExpirationMinutes() {
 CaffeineSpec spec = parse("expireAfterAccess=10m");
 assertEquals(TimeUnit.MINUTES, spec.expireAfterAccessTimeUnit);
 assertEquals(10L, spec.expireAfterAccessDuration);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().expireAfterAccess(10L, TimeUnit.MINUTES),
   Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_accessExpirationHours() {
 CaffeineSpec spec = parse("expireAfterAccess=150h");
 assertEquals(TimeUnit.HOURS, spec.expireAfterAccessTimeUnit);
 assertEquals(150L, spec.expireAfterAccessDuration);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().expireAfterAccess(150L, TimeUnit.HOURS), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_writeExpirationMinutes() {
 CaffeineSpec spec = parse("expireAfterWrite=10m");
 assertEquals(TimeUnit.MINUTES, spec.expireAfterWriteTimeUnit);
 assertEquals(10L, spec.expireAfterWriteDuration);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().expireAfterWrite(10L, TimeUnit.MINUTES), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_accessExpirationSeconds() {
 CaffeineSpec spec = parse("expireAfterAccess=10s");
 assertEquals(TimeUnit.SECONDS, spec.expireAfterAccessTimeUnit);
 assertEquals(10L, spec.expireAfterAccessDuration);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().expireAfterAccess(10L, TimeUnit.SECONDS),
   Caffeine.from(spec));
}

代码示例来源: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

public void testParse_accessExpirationAndWriteExpiration() {
 CaffeineSpec spec = parse("expireAfterAccess=10s,expireAfterWrite=9m");
 assertEquals(TimeUnit.MINUTES, spec.expireAfterWriteTimeUnit);
 assertEquals(9L, spec.expireAfterWriteDuration);
 assertEquals(TimeUnit.SECONDS, spec.expireAfterAccessTimeUnit);
 assertEquals(10L, spec.expireAfterAccessDuration);
 assertCaffeineEquivalence(
   Caffeine.newBuilder()
    .expireAfterAccess(10L, TimeUnit.SECONDS)
    .expireAfterWrite(9L, TimeUnit.MINUTES),
   Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_maximumWeight() {
 CaffeineSpec spec = parse("maximumWeight=9000");
 assertEquals(spec.initialCapacity, UNSET_INT);
 assertEquals(9000, spec.maximumWeight);
 assertNull(spec.keyStrength);
 assertNull(spec.valueStrength);
 assertNull(spec.expireAfterWriteTimeUnit);
 assertNull(spec.expireAfterAccessTimeUnit);
 assertNull(spec.refreshAfterWriteTimeUnit);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().maximumWeight(9000), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_maximumSize() {
 CaffeineSpec spec = parse("maximumSize=9000");
 assertEquals(spec.initialCapacity, UNSET_INT);
 assertEquals(9000, spec.maximumSize);
 assertNull(spec.keyStrength);
 assertNull(spec.valueStrength);
 assertNull(spec.expireAfterWriteTimeUnit);
 assertNull(spec.expireAfterAccessTimeUnit);
 assertNull(spec.refreshAfterWriteTimeUnit);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().maximumSize(9000), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_empty() {
 CaffeineSpec spec = parse("");
 assertEquals(spec.initialCapacity, UNSET_INT);
 assertEquals(spec.maximumSize, UNSET_INT);
 assertEquals(spec.maximumWeight, UNSET_INT);
 assertNull(spec.keyStrength);
 assertNull(spec.valueStrength);
 assertNull(spec.expireAfterAccessTimeUnit);
 assertNull(spec.expireAfterWriteTimeUnit);
 assertNull(spec.refreshAfterWriteTimeUnit);
 assertCaffeineEquivalence(Caffeine.newBuilder(), Caffeine.from(spec));
}

代码示例来源:origin: ben-manes/caffeine

public void testParse_softValues() {
 CaffeineSpec spec = parse("softValues");
 assertEquals(spec.initialCapacity, UNSET_INT);
 assertEquals(spec.maximumSize, UNSET_INT);
 assertEquals(spec.maximumWeight, UNSET_INT);
 assertNull(spec.keyStrength);
 assertEquals(Strength.SOFT, spec.valueStrength);
 assertNull(spec.expireAfterWriteTimeUnit);
 assertNull(spec.expireAfterAccessTimeUnit);
 assertNull(spec.refreshAfterWriteTimeUnit);
 assertCaffeineEquivalence(
   Caffeine.newBuilder().softValues(), Caffeine.from(spec));
}

相关文章