diff --git a/src/main/kotlin/com/wolt/utils/ktor/idempotency/IdempotencyPlugin.kt b/src/main/kotlin/com/wolt/utils/ktor/idempotency/IdempotencyPlugin.kt index 4bcaa74..26ffccd 100644 --- a/src/main/kotlin/com/wolt/utils/ktor/idempotency/IdempotencyPlugin.kt +++ b/src/main/kotlin/com/wolt/utils/ktor/idempotency/IdempotencyPlugin.kt @@ -31,13 +31,15 @@ val IdempotencyPlugin = pluginConfig.idempotentResponseRepository ?: throw IllegalArgumentException("IdempotentRequestRepository must be provided") - CleanUpWorker( - scope = pluginConfig.cleanUpWorkerScope, - jitter = pluginConfig.cleanUpWorkerJitter, - interval = pluginConfig.cleanUpWorkerInterval, - idempotentResponseRepository = responseRepository, - storedResponseTTL = pluginConfig.storedResponseTTL, - ).start() + if (pluginConfig.cleanUpWorkerEnabled) { + CleanUpWorker( + scope = pluginConfig.cleanUpWorkerScope, + jitter = pluginConfig.cleanUpWorkerJitter, + interval = pluginConfig.cleanUpWorkerInterval, + idempotentResponseRepository = responseRepository, + storedResponseTTL = pluginConfig.storedResponseTTL, + ).start() + } val logger = KotlinLogging.logger {} diff --git a/src/main/kotlin/com/wolt/utils/ktor/idempotency/PluginConfiguration.kt b/src/main/kotlin/com/wolt/utils/ktor/idempotency/PluginConfiguration.kt index 74de7ec..a1243cf 100644 --- a/src/main/kotlin/com/wolt/utils/ktor/idempotency/PluginConfiguration.kt +++ b/src/main/kotlin/com/wolt/utils/ktor/idempotency/PluginConfiguration.kt @@ -45,6 +45,12 @@ class PluginConfiguration { HttpMethod.Patch, ) + /** + * Flag that controls execution of clean up worker. + * Clean up worker is enabled by default, but consider disabling it if your response repository can leverage a built-in expiration mechanism (e.g. Redis key expiration time). + */ + var cleanUpWorkerEnabled = true + /** * The coroutine scope for the worker that cleans up expired responses. */