Skip to content

How to convert ConcurrentLinkedHashMap to Caffeine #1341

Answered by ben-manes
nagraj321 asked this question in Q&A
Discussion options

You must be logged in to vote

You may want to review the migration guide. I would probably rewrite your snippet as,

public class TestResultCache {
  private final Cache<String, TestBucket> buckets;

  public TestResultCache() {
    buckets = Caffeine.newBuilder()
        .removalListener((String key, TestBucket value, RemovalCause cause) -> {
          if (cause.wasEvicted()) {
            // ...
          }
        })
        .maximumSize(capacity)
        .build();
  }
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nagraj321
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