本文整理了Java中com.github.benmanes.caffeine.cache.Caffeine.refreshAfterWrite()
方法的一些代码示例,展示了Caffeine.refreshAfterWrite()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Caffeine.refreshAfterWrite()
方法的具体详情如下:
包路径:com.github.benmanes.caffeine.cache.Caffeine
类名称:Caffeine
方法名:refreshAfterWrite
[英]Specifies that active entries are eligible for automatic refresh once a fixed duration has elapsed after the entry's creation, or the most recent replacement of its value. The semantics of refreshes are specified in LoadingCache#refresh, and are performed by calling CacheLoader#reload.
Automatic refreshes are performed when the first stale request for an entry occurs. The request triggering refresh will make an asynchronous call to CacheLoader#reload and immediately return the old value.
Note:all exceptions thrown during refresh will be logged and then swallowed.
If you can represent the duration as a java.time.Duration (which should be preferred when feasible), use #refreshAfterWrite(Duration) instead.
[中]指定活动项在创建后经过固定的持续时间或最近替换其值后,可以自动刷新。刷新的语义在LoadingCache#refresh中指定,并通过调用CacheLoader#refresh来执行。
当第一个过时的条目请求出现时,将执行自动刷新。触发刷新的请求将对CacheLoader#reload进行异步调用,并立即返回旧值。
注意:刷新期间引发的所有异常都将被记录,然后被删除。
如果可以将持续时间表示为java。时间持续时间(可行时应首选),改用#refreshAfterWrite(持续时间)。
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void refreshAfterWrite_twice() {
Caffeine.newBuilder().refreshAfterWrite(1, TimeUnit.MILLISECONDS)
.refreshAfterWrite(1, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: ben-manes/caffeine
private void configureRefreshAfterWrite() {
if (config.getRefreshAfterWrite().isPresent()) {
caffeine.refreshAfterWrite(config.getRefreshAfterWrite().getAsLong(), TimeUnit.NANOSECONDS);
}
}
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void refreshAfterWrite_duration_twice() {
Caffeine.newBuilder().refreshAfterWrite(Duration.ofMillis(1))
.refreshAfterWrite(Duration.ofMillis(1));
}
代码示例来源:origin: ben-manes/caffeine
/**
* Specifies that active entries are eligible for automatic refresh once a fixed duration has
* elapsed after the entry's creation, or the most recent replacement of its value. The semantics
* of refreshes are specified in {@link LoadingCache#refresh}, and are performed by calling {@link
* CacheLoader#reload}.
* <p>
* Automatic refreshes are performed when the first stale request for an entry occurs. The request
* triggering refresh will make an asynchronous call to {@link CacheLoader#reload} and immediately
* return the old value.
* <p>
* <b>Note:</b> <i>all exceptions thrown during refresh will be logged and then swallowed</i>.
*
* @param duration the length of time after an entry is created that it should be considered
* stale, and thus eligible for refresh
* @return this {@code Caffeine} instance (for chaining)
* @throws IllegalArgumentException if {@code duration} is negative
* @throws IllegalStateException if the refresh interval was already set
* @throws ArithmeticException for durations greater than +/- approximately 292 years
*/
@NonNull
public Caffeine<K, V> refreshAfterWrite(@NonNull Duration duration) {
return refreshAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS);
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalArgumentException.class)
public void refreshAfterWrite_zero() {
Caffeine.newBuilder().refreshAfterWrite(0, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalArgumentException.class)
public void refreshAfterWrite_duration_negative() {
Caffeine.newBuilder().refreshAfterWrite(Duration.ofMillis(-1));
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalArgumentException.class)
public void refreshAfterWrite_duration_zero() {
Caffeine.newBuilder().refreshAfterWrite(Duration.ofMillis(0));
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalArgumentException.class)
public void refreshAfterWrite_negative() {
Caffeine.newBuilder().refreshAfterWrite(-1, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: ben-manes/caffeine
@GwtIncompatible // java.time.Duration
public void testRefresh_setTwice_duration() {
Caffeine<Object, Object> builder =
Caffeine.newBuilder().refreshAfterWrite(java.time.Duration.ofSeconds(3600));
try {
// even to the same value is not allowed
builder.refreshAfterWrite(java.time.Duration.ofSeconds(3600));
fail();
} catch (IllegalStateException expected) {
}
}
代码示例来源:origin: ben-manes/caffeine
@GwtIncompatible("refreshAfterWrite")
public void testRefresh_setTwice() {
Caffeine<Object, Object> builder =
Caffeine.newBuilder().refreshAfterWrite(3600, SECONDS);
try {
// even to the same value is not allowed
builder.refreshAfterWrite(3600, SECONDS);
fail();
} catch (IllegalStateException expected) {}
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void refreshAfterWrite_duration_noCacheLoader() {
Caffeine.newBuilder().refreshAfterWrite(Duration.ofMillis(1)).build();
}
代码示例来源:origin: ben-manes/caffeine
@Test
public void refreshAfterWrite_duration() {
Caffeine<Object, Object> builder = Caffeine.newBuilder()
.refreshAfterWrite(Duration.ofMillis(1));
assertThat(builder.getRefreshAfterWriteNanos(), is(TimeUnit.MILLISECONDS.toNanos(1)));
builder.build(k -> k);
}
代码示例来源:origin: ben-manes/caffeine
@Test
public void refreshAfterWrite() {
Caffeine<Object, Object> builder = Caffeine.newBuilder()
.refreshAfterWrite(1, TimeUnit.MILLISECONDS);
assertThat(builder.getRefreshAfterWriteNanos(), is(TimeUnit.MILLISECONDS.toNanos(1)));
builder.build(k -> k);
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void refreshAfterWrite_noCacheLoader() {
Caffeine.newBuilder().refreshAfterWrite(1, TimeUnit.MILLISECONDS).build();
}
代码示例来源:origin: ben-manes/caffeine
@GwtIncompatible // java.time.Duration
public void testRefresh_zero_duration() {
Caffeine<Object, Object> builder = Caffeine.newBuilder();
try {
builder.refreshAfterWrite(java.time.Duration.ZERO);
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
@GwtIncompatible("refreshAfterWrite")
public void testRefresh_zero() {
Caffeine<Object, Object> builder = Caffeine.newBuilder();
try {
builder.refreshAfterWrite(0, SECONDS);
fail();
} catch (IllegalArgumentException expected) {}
}
代码示例来源:origin: ben-manes/caffeine
builder.refreshAfterWrite(refreshAfterWriteDuration, refreshAfterWriteTimeUnit);
代码示例来源:origin: ben-manes/caffeine
builder.refreshAfterWrite(refresh.duration, refresh.unit);
代码示例来源:origin: ben-manes/caffeine
@GwtIncompatible // java.time.Duration
public void testLargeDurations() {
java.time.Duration threeHundredYears = java.time.Duration.ofDays(365 * 300);
Caffeine<Object, Object> builder = Caffeine.newBuilder();
try {
builder.expireAfterWrite(threeHundredYears);
fail();
} catch (ArithmeticException expected) {
}
try {
builder.expireAfterAccess(threeHundredYears);
fail();
} catch (ArithmeticException expected) {
}
try {
builder.refreshAfterWrite(threeHundredYears);
fail();
} catch (ArithmeticException expected) {
}
}
内容来源于网络,如有侵权,请联系作者删除!