-
We previously utilized ConcurrentLinkedHashMap in our project, part of ActiveMQ 5.14.X. As we are upgrading to ActiveMQ 5.16.7, we've observed that ConcurrentLinkedHashMap has been replaced with Caffeine. Consequently, we seek guidance on adapting our existing code to support Caffeine. The following is a snippet of the original code: public class TestResultCache implements EvictionListener<String, TestBucket> {
protected ConcurrentLinkedHashMap<String, TestBucket> bucketMap;
bucketMap = new ConcurrentLinkedHashMap
.Builder<String, SessionBucket>()
.maximumWeightedCapacity(capacity)
.listener(this)
.build();
} To migrate to Caffeine, we can make the necessary adjustments: |
Beta Was this translation helpful? Give feedback.
Answered by
ben-manes
Nov 27, 2023
Replies: 1 comment 2 replies
-
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();
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ben-manes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may want to review the migration guide. I would probably rewrite your snippet as,