Will TTL play a role in cleaning up old values if replace before TTL? #570
Answered
by
ben-manes
ShanmugamC
asked this question in
Q&A
-
Hi Team, E.g: |
Beta Was this translation helpful? Give feedback.
Answered by
ben-manes
Jul 5, 2021
Replies: 1 comment 5 replies
-
This depends on your expiration setting.
If you want an entry to expire only after creation, regardless of subsequent reads or writes, then you should use Caffeine.newBuilder()
.expireAfter(new Expiry<Key, Graph>() {
public long expireAfterCreate(Key key, Graph graph, long currentTime) {
return TimeUnit.HOURS.toNanos(12);
}
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(); |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
ben-manes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This depends on your expiration setting.
expireAfterWrite
will reset the entry's lifetime on every update, causing it to have a 12 hour duration.expireAfterAccess
will reset the entry's lifetime on every read or write.expireAfter(expiry)
will reset to the return value ofExpiry.expireAfterUpdate
.If you want an entry to expire only after creation, regardless of subsequent reads or writes, then you should use
expireAfter(expiry)
.