expireAfter

Age-based Cache expiration strategy.

General behavior

The cache starts a worker in scope. Every duration, all values which have not been updated for at least duration are expired in the previous layer.

This layer considers any non-loading value returned by get to be new.

If scope is cancelled, requests made to this cache continue to work as normal, but no values are ever expired anymore.

Example

val scope: CoroutineScope = …

val powersOfTwo = cache<Int, Int> { it * 2 }
.cachedInMemory(scope.coroutineContext.job)
.expireAfter(10.minutes, scope, clock)