Skip to content
Bluetape4k docs1.11

Retry, failures, and lifecycle

Latest stable Based on Bluetape4k release 1.11.0

withResilience decorates a common Near Cache interface with Resilience4j retry.

val resilient = cache.withResilience {
retryMaxAttempts = 3
retryWaitDuration = Duration.ofMillis(200)
retryExponentialBackoff = true
getFailureStrategy = GetFailureStrategy.RETURN_FRONT_OR_NULL
}

The defaults are three attempts, a 500 ms initial wait, and exponential backoff. Attempts and duration must be positive. Verify operation idempotency before retrying side effects.

OperationRETURN_FRONT_OR_NULLPROPAGATE_EXCEPTION
getlog and return nullpropagate the last exception
getAlllog and return an empty mappropagate the last exception
containsKeylog and return falsepropagate the last exception

Fallback makes a missing entry indistinguishable from a failed backend. Use it only when availability has priority, and monitor an error counter or the warning logs.

Mutation operations such as put, replace, remove, and clearAll propagate after retry exhaustion. Silently dropping a write could leave local and back tiers inconsistent.

ResilientSuspendNearCacheDecorator excludes CancellationException from retry. It rethrows cancellation even under RETURN_FRONT_OR_NULL, including cancellation during put and close.

val job = launch { resilient.get("slow-key") }
job.cancelAndJoin()

Converting cancellation to a fallback would keep cache work alive after its parent scope has stopped.

The blocking decorator logs and ignores ordinary delegate close failures. The suspend decorator does the same for ordinary exceptions but rethrows cancellation. Ignoring a close error does not prove that connections and threads were released; inspect provider metrics and shutdown logs.

Confirm whether a factory owns the remote client or only the cache wrapper. Avoid both closing a shared client too early and leaving an unowned client open.

Retry repeats a failed remote call. It does not merge concurrent misses for a hot key and may amplify a slow backend. Combine same-key memoization or provider loader merging with bounded retry, timeout, and source-store protection.