removalListener not getting invoked #650
-
I am trying to get a removalListener as below but it is never being invoked. Below is sample code what I tried. Any suggestion ?
Using caffeine 2.9.2 with JAVA 8 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
By default the cache defers to an executor for non-critical path logic, like notifying the removal listener, since we don't know how expensive that work is and do not want to impact the caller if it would increase user-facing latencies. Most likely your test is completing before the ForkJoinPool.commonPool() executes the work. You can use |
Beta Was this translation helpful? Give feedback.
By default the cache defers to an executor for non-critical path logic, like notifying the removal listener, since we don't know how expensive that work is and do not want to impact the caller if it would increase user-facing latencies. Most likely your test is completing before the ForkJoinPool.commonPool() executes the work. You can use
Caffeine.executor(Runnable::run)
to disable this behavior (as the cache's own logic is fast) or wait for the work to finish (e.g. using Awaitility).