Skip to content

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
Discussion options

You must be logged in to vote

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 of Expiry.expireAfterUpdate.

If you want an entry to expire only after creation, regardless of subsequent reads or writes, then you should use expireAfter(expiry).

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, 
      …

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ShanmugamC
Comment options

@ben-manes
Comment options

@ShanmugamC
Comment options

@ShanmugamC
Comment options

@ben-manes
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants