每次有效咖啡因的示例

时间:2020-08-14 17:30:28

标签: java caffeine caffeine-cache

在咖啡因中有没有使用每个密钥有效期的示例?

我看到下面的示例-这是否意味着我们要为每个键创建一个Caffeine缓存实例?

https://github.com/ben-manes/caffeine/issues/114#issuecomment-300602200

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        app:elevation="8dp"

我查看了实现,并了解如何在内部使用expiry接口的实现。

所以说我的图形对象有一个有效期限的方法..这会是正确的用法吗?

1.2.0

现在任何时候我都可以执行以下操作-插入的密钥将启用每个密钥有效期-

Caffeine.newBuilder()
.expireAfter(new Expiry<Key, Graph>() {
  public long expireAfterCreate(Key key, Graph graph, long currentTime) {
    return (graph instanceof NullGraph)
        ? TimeUnit.MINUTES.toNanos(1)
        : TimeUnit.MINUTES.toNanos(10);
  }
  public long expireAfterUpdate(Key key, Graph graph, 
      long currentTime, long currentDuration) {
    return currentDuration;
  }
  public long expireAfterRead(Key key, Graph graph,
      long currentTime, long currentDuration) {
    return currentDuration;
  }
})
.build(key -> createExpensiveGraph(key));

0 个答案:

没有答案