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

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

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

Caffeine.expireAfter介绍

[英]Specifies that each entry should be automatically removed from the cache once a duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read. The expiration time is reset by all cache read and write operations (including Cache.asMap().get(Object) and Cache.asMap().put(K, V)), but not by operations on the collection-views of Cache#asMap.

Expired entries may be counted in Cache#estimatedSize(), but will never be visible to read or write operations. Expired entries are cleaned up as part of the routine maintenance described in the class javadoc.
[中]指定在创建条目、最近一次替换其值或最后一次读取之后,一旦持续时间已过,则应自动从缓存中删除每个条目。过期时间由所有缓存读写操作(包括cache.asMap())重置。获取(对象)和缓存。asMap()。put(K,V)),但不是通过对Cache#asMap的集合视图进行操作。
过期的条目可能会在缓存#estimatedSize()中计数,但对读写操作而言永远不会可见。过期条目将作为javadoc类中描述的日常维护的一部分进行清理。

代码示例

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfterAccess_expiry() {
 Caffeine.newBuilder().expireAfter(expiry).expireAfterAccess(1, TimeUnit.MILLISECONDS);
}

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfter_write() {
 Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MILLISECONDS).expireAfter(expiry);
}

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfter_twice() {
 Caffeine.newBuilder().expireAfter(expiry).expireAfter(expiry);
}

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

builder.expireAfter(expiry);

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

builder.expireAfter(context.expiry);

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfterWrite_expiry() {
 Caffeine.newBuilder().expireAfter(expiry).expireAfterWrite(1, TimeUnit.MILLISECONDS);
}

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfter_access() {
 Caffeine.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).expireAfter(expiry);
}

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

@Test(expectedExceptions = NullPointerException.class)
public void expireAfter_null() {
 Caffeine.newBuilder().expireAfter(null);
}

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

builder.expireAfter(expiry);

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfterWrite_duration_expiry() {
 Caffeine.newBuilder().expireAfter(expiry).expireAfterWrite(Duration.ofMillis(1));
}

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

@Test(expectedExceptions = IllegalStateException.class)
public void expireAfterAccess_duration_expiry() {
 Caffeine.newBuilder().expireAfter(expiry).expireAfterAccess(Duration.ofMillis(1));
}

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

@Test
public void expireAfter() {
 Caffeine<?, ?> builder = Caffeine.newBuilder().expireAfter(expiry);
 assertThat(builder.expiry, is(expiry));
 builder.build();
}

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

/** Configures the write expiration and returns if set. */
private boolean configureExpireVariably() {
 config.getExpiryFactory().ifPresent(factory -> {
  Expiry<K, V> expiry = factory.create();
  caffeine.expireAfter(new Expiry<K, Expirable<V>>() {
   @Override public long expireAfterCreate(K key, Expirable<V> expirable, long currentTime) {
    return expiry.expireAfterCreate(key, expirable.get(), currentTime);
   }
   @Override public long expireAfterUpdate(K key, Expirable<V> expirable,
     long currentTime, long currentDuration) {
    return expiry.expireAfterUpdate(key, expirable.get(), currentTime, currentDuration);
   }
   @Override public long expireAfterRead(K key, Expirable<V> expirable,
     long currentTime, long currentDuration) {
    return expiry.expireAfterRead(key, expirable.get(), currentTime, currentDuration);
   }
  });
 });
 return config.getExpireAfterWrite().isPresent();
}

代码示例来源:origin: alibaba/jetcache

final boolean isExpireAfterAccess = config.isExpireAfterAccess();
final long expireAfterAccess = config.getExpireAfterAccessInMillis();
builder.expireAfter(new Expiry<Object, CacheValueHolder>() {
  private long getRestTimeInNanos(CacheValueHolder value) {
    long now = System.currentTimeMillis();

代码示例来源:origin: org.apereo.cas/cas-server-support-saml-idp-metadata

public SamlRegisteredServiceDefaultCachingMetadataResolver(final long metadataCacheExpirationMinutes,
                              final SamlRegisteredServiceMetadataResolverCacheLoader loader) {
  this.chainingMetadataResolverCacheLoader = loader;
  this.cache = Caffeine.newBuilder()
    .maximumSize(MAX_CACHE_SIZE)
    .expireAfter(new SamlRegisteredServiceMetadataExpirationPolicy(metadataCacheExpirationMinutes))
    .build(this.chainingMetadataResolverCacheLoader);
}

代码示例来源:origin: com.github.ben-manes.caffeine/jcache

/** Configures the write expiration and returns if set. */
private boolean configureExpireVariably() {
 config.getExpiryFactory().ifPresent(factory -> {
  Expiry<K, V> expiry = factory.create();
  caffeine.expireAfter(new Expiry<K, Expirable<V>>() {
   @Override public long expireAfterCreate(K key, Expirable<V> expirable, long currentTime) {
    return expiry.expireAfterCreate(key, expirable.get(), currentTime);
   }
   @Override public long expireAfterUpdate(K key, Expirable<V> expirable,
     long currentTime, long currentDuration) {
    return expiry.expireAfterUpdate(key, expirable.get(), currentTime, currentDuration);
   }
   @Override public long expireAfterRead(K key, Expirable<V> expirable,
     long currentTime, long currentDuration) {
    return expiry.expireAfterRead(key, expirable.get(), currentTime, currentDuration);
   }
  });
 });
 return config.getExpireAfterWrite().isPresent();
}

代码示例来源:origin: com.erudika/para-server

/**
 * Default constructor.
 */
public CaffeineCache() {
  cache = Caffeine.newBuilder()
    .maximumSize(Config.getConfigInt("caffeine.cache_size", 10000))
    .expireAfter(new Expiry<String, Object>() {
      public long expireAfterCreate(String key, Object value, long currentTime) {
        return TimeUnit.MINUTES.toNanos(DEFAULT_EXPIRATION_MIN);
      }
      public long expireAfterUpdate(String key, Object value, long currentTime, long currentDuration) {
        return currentDuration;
      }
      public long expireAfterRead(String key, Object value, long currentTime, long currentDuration) {
        return currentDuration;
      }
    })
    .build();
}

代码示例来源:origin: Erudika/para

/**
 * Default constructor.
 */
public CaffeineCache() {
  cache = Caffeine.newBuilder()
    .maximumSize(Config.getConfigInt("caffeine.cache_size", 10000))
    .expireAfter(new Expiry<String, Object>() {
      public long expireAfterCreate(String key, Object value, long currentTime) {
        return TimeUnit.MINUTES.toNanos(DEFAULT_EXPIRATION_MIN);
      }
      public long expireAfterUpdate(String key, Object value, long currentTime, long currentDuration) {
        return currentDuration;
      }
      public long expireAfterRead(String key, Object value, long currentTime, long currentDuration) {
        return currentDuration;
      }
    })
    .build();
}

代码示例来源:origin: org.apereo.cas/cas-server-core-tickets-api

public CachingTicketRegistry(final CipherExecutor cipherExecutor, final LogoutManager logoutManager) {
  super(cipherExecutor);
  this.storage = Caffeine.newBuilder()
    .initialCapacity(INITIAL_CACHE_SIZE)
    .maximumSize(MAX_CACHE_SIZE)
    .expireAfter(new CachedTicketExpirationPolicy()).removalListener(new CachedTicketRemovalListener())
    .build(s -> {
      LOGGER.error("Load operation of the cache is not supported.");
      return null;
    });
  this.mapInstance = this.storage.asMap();
  this.logoutManager = logoutManager;
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

private Cache<CacheKey, MemCachePersistenceObject> buildCache() {
  return Caffeine.newBuilder()
      .maximumWeight(maxSizeInMb * MEGABYTE)
      .weigher(new MemCacheEntryWeigher())
      .expireAfter(expiryPolicy)
      .removalListener(new MemCacheEntryRemovalListener())
      .recordStats()
      .build();
}

相关文章