diff --git a/aedile-core/src/main/kotlin/com/sksamuel/aedile/core/config.kt b/aedile-core/src/main/kotlin/com/sksamuel/aedile/core/config.kt index e38b8ad..0c439da 100644 --- a/aedile-core/src/main/kotlin/com/sksamuel/aedile/core/config.kt +++ b/aedile-core/src/main/kotlin/com/sksamuel/aedile/core/config.kt @@ -23,15 +23,30 @@ fun Caffeine.scheduler(scheduler: Scheduler): Caffeine { } } +/** + * Specifies a listener that is notified each time an entry is removed. + * See full docs at [Caffeine.removalListener]. + */ +fun Caffeine.removalListener( + scope: CoroutineScope, + listener: suspend (K?, V?, RemovalCause) -> Unit, +): Caffeine { + return removalListener { key, value, cause -> + scope.launch { + listener.invoke(key, value, cause) + } + } +} + /** * Specifies a listener that is notified each time an entry is evicted. * See full docs at [Caffeine.evictionListener]. */ -fun Caffeine.removalListener( +fun Caffeine.evictionListener( scope: CoroutineScope, - listener: suspend (K?, V?, RemovalCause) -> Unit + listener: suspend (K?, V?, RemovalCause) -> Unit, ): Caffeine { - return removalListener { key, value, cause -> + return evictionListener { key, value, cause -> scope.launch { listener.invoke(key, value, cause) }