/** Configures the write expiration and returns if set. */ private boolean configureExpireAfterWrite() { if (config.getExpireAfterWrite().isPresent()) { caffeine.expireAfterWrite(config.getExpireAfterWrite().getAsLong(), TimeUnit.NANOSECONDS); } return config.getExpireAfterWrite().isPresent(); }
static void checkEagerExpiration(CaffeineConfiguration<?, ?> config) { assertThat(config.getExpireAfterWrite().getAsLong(), is(TimeUnit.MINUTES.toNanos(1))); assertThat(config.getExpireAfterAccess().getAsLong(), is(TimeUnit.MINUTES.toNanos(5))); }
/** 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(); }
/** Configures the write expiration and returns if set. */ private boolean configureExpireAfterWrite() { if (config.getExpireAfterWrite().isPresent()) { caffeine.expireAfterWrite(config.getExpireAfterWrite().getAsLong(), TimeUnit.NANOSECONDS); } return config.getExpireAfterWrite().isPresent(); }
/** 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(); }