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

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

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

Cache.cleanUp介绍

[英]Performs any pending maintenance operations needed by the cache. Exactly which activities are performed -- if any -- is implementation-dependent.
[中]执行缓存所需的任何挂起的维护操作。具体执行哪些活动(如果有)取决于实现。

代码示例

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

@Override
public void cleanUp() {
 cache.cleanUp();
}

代码示例来源:origin: apache/incubator-druid

@Override
@LifecycleStop
public void close() throws IOException
{
 cache.cleanUp();
}

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

public void cleanUp() {
 cache.cleanUp();
}

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

private void checkContainsInOrder(Cache<Integer, Integer> cache, Integer... expect) {
 cache.cleanUp();
 List<Integer> evictionList = ImmutableList.copyOf(
   cache.policy().eviction().get().coldest(Integer.MAX_VALUE).keySet());
 assertThat(cache.asMap().size(), is(equalTo(expect.length)));
 assertThat(cache.asMap().keySet(), containsInAnyOrder(expect));
 assertThat(evictionList, is(equalTo(asList(expect))));
}

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

/** Ensures that that all the pending work is performed (Guava limits work per cycle). */
 private static void awaitFullCleanup(Cache<?, ?> cache) {
  for (;;) {
   long size = cache.estimatedSize();
   cache.cleanUp();

   if (size == cache.estimatedSize()) {
    break;
   }
  }
 }
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL,
  expiry = CacheExpiry.WRITE, expiryTime = Expire.ONE_MINUTE)
public void putIfAbsent_insert(Cache<Integer, Integer> cache, CacheContext context,
  VarExpiration<Integer, Integer> expireAfterVar) {
 Integer key = context.absentKey();
 Integer value = context.absentValue();
 assertThat(expireAfterVar.putIfAbsent(key, value, Duration.ofMinutes(2L)), is(true));
 assertThat(cache.getIfPresent(key), is(value));
 assertThat(expireAfterVar.getExpiresAfter(key), is(Optional.of(Duration.ofMinutes(2L))));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(1L));
}

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

@CacheSpec
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void cleanup(Cache<Integer, Integer> cache, CacheContext context) {
 cache.cleanUp();
}

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

@Test(dataProvider = "caches")
@CacheSpec(keys = ReferenceType.STRONG, values = {ReferenceType.WEAK, ReferenceType.SOFT},
  implementation = Implementation.Caffeine, expireAfterAccess = Expire.DISABLED,
  expireAfterWrite = Expire.DISABLED, maximumSize = Maximum.DISABLED,
  weigher = CacheWeigher.DEFAULT, population = Population.FULL, stats = Stats.ENABLED,
  compute = Compute.SYNC, removalListener = Listener.CONSUMING, writer = Writer.EXCEPTIONAL)
public void cleanUp_writerFails(Cache<Integer, Integer> cache, CacheContext context) {
 context.clear();
 GcFinalization.awaitFullGc();
 cache.cleanUp();
 context.disableRejectingCacheWriter();
 assertThat(cache.asMap().isEmpty(), is(false));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, expireAfterAccess = Expire.ONE_MINUTE)
public void setExpiresAfter_duration(Cache<Integer, Integer> cache, CacheContext context,
  @ExpireAfterAccess Expiration<Integer, Integer> expireAfterAccess) {
 expireAfterAccess.setExpiresAfter(Duration.ofMinutes(2L));
 assertThat(expireAfterAccess.getExpiresAfter(), is(Duration.ofMinutes(2L)));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(context.initialSize()));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine,
  mustExpireWithAnyOf = AFTER_WRITE, expireAfterWrite = Expire.ONE_MINUTE)
public void setExpiresAfter_duration(Cache<Integer, Integer> cache, CacheContext context,
  @ExpireAfterWrite Expiration<Integer, Integer> expireAfterWrite) {
 expireAfterWrite.setExpiresAfter(Duration.ofMinutes(2));
 assertThat(expireAfterWrite.getExpiresAfter(), is(Duration.ofMinutes(2L)));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(context.initialSize()));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL,
  expiry = CacheExpiry.WRITE, expiryTime = Expire.ONE_MINUTE)
public void putIfAbsent_present(Cache<Integer, Integer> cache, CacheContext context,
  VarExpiration<Integer, Integer> expireAfterVar) {
 Integer key = context.firstKey();
 Integer value = context.absentValue();
 assertThat(expireAfterVar.putIfAbsent(key, value, Duration.ofMinutes(2L)), is(false));
 assertThat(cache.getIfPresent(key), is(context.original().get(key)));
 assertThat(expireAfterVar.getExpiresAfter(key), is(Optional.of(Duration.ofMinutes(1L))));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(0L));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL,
  expiry = CacheExpiry.WRITE, expiryTime = Expire.ONE_MINUTE)
public void put_insert(Cache<Integer, Integer> cache, CacheContext context,
  VarExpiration<Integer, Integer> expireAfterVar) {
 Integer key = context.absentKey();
 Integer value = context.absentValue();
 expireAfterVar.put(key, value, Duration.ofMinutes(2L));
 assertThat(cache.getIfPresent(key), is(value));
 assertThat(expireAfterVar.getExpiresAfter(key), is(Optional.of(Duration.ofMinutes(2L))));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(1L));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL,
  expiry = CacheExpiry.WRITE, expiryTime = Expire.ONE_MINUTE)
public void put_replace(Cache<Integer, Integer> cache, CacheContext context,
  VarExpiration<Integer, Integer> expireAfterVar) {
 Integer key = context.firstKey();
 Integer value = context.absentValue();
 expireAfterVar.put(key, value, Duration.ofMinutes(2L));
 assertThat(cache.getIfPresent(key), is(value));
 assertThat(expireAfterVar.getExpiresAfter(key), is(Optional.of(Duration.ofMinutes(2L))));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(1L));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL,
  expiry = CacheExpiry.MOCKITO, expiryTime = Expire.ONE_MINUTE)
public void setExpiresAfter_duration(Cache<Integer, Integer> cache, CacheContext context,
  VarExpiration<Integer, Integer> expireAfterVar) {
 expireAfterVar.setExpiresAfter(context.firstKey(), Duration.ofMinutes(2L));
 assertThat(expireAfterVar.getExpiresAfter(context.firstKey()),
   is(Optional.of(Duration.ofMinutes(2L))));
 expireAfterVar.setExpiresAfter(context.absentKey(), Duration.ofMinutes(4L));
 assertThat(expireAfterVar.getExpiresAfter(context.absentKey()), is(Optional.empty()));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(1L));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, expireAfterAccess = Expire.ONE_MINUTE)
public void setExpiresAfter(Cache<Integer, Integer> cache, CacheContext context,
  @ExpireAfterAccess Expiration<Integer, Integer> expireAfterAccess) {
 expireAfterAccess.setExpiresAfter(2, TimeUnit.MINUTES);
 assertThat(expireAfterAccess.getExpiresAfter(TimeUnit.MINUTES), is(2L));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(context.initialSize()));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine,
  mustExpireWithAnyOf = AFTER_WRITE, expireAfterWrite = Expire.ONE_MINUTE)
public void setExpiresAfter(Cache<Integer, Integer> cache, CacheContext context,
  @ExpireAfterWrite Expiration<Integer, Integer> expireAfterWrite) {
 expireAfterWrite.setExpiresAfter(2, TimeUnit.MINUTES);
 assertThat(expireAfterWrite.getExpiresAfter(TimeUnit.MINUTES), is(2L));
 context.ticker().advance(90, TimeUnit.SECONDS);
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(context.initialSize()));
}

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

@Test(dataProvider = "caches")
@CacheSpec(mustExpireWithAnyOf = { AFTER_ACCESS, VARIABLE },
  expiry = { CacheExpiry.DISABLED, CacheExpiry.ACCESS }, expiryTime = Expire.ONE_MINUTE,
  expireAfterAccess = Expire.ONE_MINUTE, population = { Population.PARTIAL, Population.FULL })
public void getAllPresent(Cache<Integer, Integer> cache, CacheContext context) {
 context.ticker().advance(30, TimeUnit.SECONDS);
 cache.getAllPresent(context.firstMiddleLastKeys());
 context.ticker().advance(45, TimeUnit.SECONDS);
 assertThat(cache.getAllPresent(context.firstMiddleLastKeys()).size(), is(3));
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(3L));
 long count = context.initialSize() - 3;
 assertThat(cache, hasRemovalNotifications(context, count, RemovalCause.EXPIRED));
 verifyWriter(context, (verifier, writer) -> verifier.deletions(count, RemovalCause.EXPIRED));
}

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

@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine, keys = ReferenceType.STRONG,
  population = Population.FULL, expiryTime = Expire.ONE_MINUTE,
  mustExpireWithAnyOf = { AFTER_ACCESS, AFTER_WRITE, VARIABLE },
  expiry = { CacheExpiry.DISABLED, CacheExpiry.CREATE, CacheExpiry.WRITE, CacheExpiry.ACCESS },
  expireAfterAccess = {Expire.DISABLED, Expire.ONE_MINUTE},
  expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE},
  compute = Compute.SYNC, writer = Writer.EXCEPTIONAL, removalListener = Listener.REJECTING)
public void cleanUp_writerFails(Cache<Integer, Integer> cache, CacheContext context) {
 context.ticker().advance(1, TimeUnit.HOURS);
 cache.cleanUp();
 context.disableRejectingCacheWriter();
 context.ticker().advance(-1, TimeUnit.HOURS);
 assertThat(cache.asMap(), equalTo(context.original()));
}

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

@Test(dataProvider = "caches")
@CacheSpec(mustExpireWithAnyOf = { AFTER_WRITE, VARIABLE },
  expireAfterWrite = { Expire.DISABLED, Expire.ONE_MINUTE },
  expiry = { CacheExpiry.DISABLED, CacheExpiry.WRITE }, expiryTime = Expire.ONE_MINUTE,
  population = { Population.PARTIAL, Population.FULL })
public void getIfPresent(Cache<Integer, Integer> cache, CacheContext context) {
 context.ticker().advance(30, TimeUnit.SECONDS);
 cache.getIfPresent(context.firstKey());
 context.ticker().advance(45, TimeUnit.SECONDS);
 assertThat(cache.getIfPresent(context.firstKey()), is(nullValue()));
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(0L));
 long count = context.initialSize();
 assertThat(cache, hasRemovalNotifications(context, count, RemovalCause.EXPIRED));
 verifyWriter(context, (verifier, writer) -> verifier.deletions(count, RemovalCause.EXPIRED));
}

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

@Test(dataProvider = "caches")
@CacheSpec(mustExpireWithAnyOf = { AFTER_ACCESS, VARIABLE },
  expiry = { CacheExpiry.DISABLED, CacheExpiry.ACCESS }, expiryTime = Expire.ONE_MINUTE,
  expireAfterAccess = Expire.ONE_MINUTE, population = { Population.PARTIAL, Population.FULL })
public void getIfPresent(Cache<Integer, Integer> cache, CacheContext context) {
 context.ticker().advance(30, TimeUnit.SECONDS);
 cache.getIfPresent(context.firstKey());
 context.ticker().advance(45, TimeUnit.SECONDS);
 assertThat(cache.getIfPresent(context.firstKey()), is(-context.firstKey()));
 assertThat(cache.getIfPresent(context.lastKey()), is(nullValue()));
 cache.cleanUp();
 assertThat(cache.estimatedSize(), is(1L));
 long count = context.initialSize() - 1;
 assertThat(cache, hasRemovalNotifications(context, count, RemovalCause.EXPIRED));
 verifyWriter(context, (verifier, writer) -> verifier.deletions(count, RemovalCause.EXPIRED));
}

相关文章