@@ -20,23 +20,7 @@ import java.util.concurrent.Executor
2020 * If the suspendable computation throws or computes a null value, then the
2121 * entry will be automatically removed.
2222 */
23- fun <K : Any , V : Any > Caffeine <in K , in V >.asCache (): Cache <K , V > {
24- val scope = CoroutineScope (Dispatchers .IO + CoroutineName (" Aedile-AsyncLoadingCache-Scope" ) + SupervisorJob ())
25- return asCache(scope)
26- }
27-
28- /* *
29- * Returns a [Cache] which suspends when requesting values.
30- *
31- * If the key is not present in the cache, it returns null, unless a compute function
32- * is provided with the key.
33- *
34- * If the suspendable computation throws or computes a null value, then the
35- * entry will be automatically removed.
36- */
37- fun <K : Any , V : Any > Caffeine <in K , in V >.asCache (scope : CoroutineScope ): Cache <K , V > {
38- return Cache (buildAsync())
39- }
23+ fun <K : Any , V : Any > Caffeine <in K , in V >.asCache (): Cache <K , V > = Cache (buildAsync())
4024
4125/* *
4226 * Returns a [LoadingCache] which uses the provided [compute] function
@@ -54,16 +38,16 @@ fun <K : Any, V : Any> Caffeine<in K, in V>.asLoadingCache(compute: suspend (K)
5438 * Returns a [LoadingCache] which uses the provided [compute] function
5539 * to compute a value, unless a specific compute has been provided with the key.
5640 *
57- * The compute function will execute on the given [scope].
41+ * The [ compute] function will execute on the given [scope].
5842 *
59- * If the suspendable computation throws or computes a null value then the
43+ * If the suspendable computation throws or computes a null value, then the
6044 * entry will be automatically removed.
6145 */
6246fun <K : Any , V : Any > Caffeine <in K , in V >.asLoadingCache (
6347 scope : CoroutineScope ,
6448 compute : suspend (K ) -> V
6549): LoadingCache <K , V > {
66- return LoadingCache (scope, true , buildAsync { key, _ -> scope.async { compute(key) }.asCompletableFuture() })
50+ return LoadingCache (buildAsync { key, _ -> scope.async { compute(key) }.asCompletableFuture() })
6751}
6852
6953/* *
@@ -92,20 +76,20 @@ fun <K : Any, V : Any> Caffeine<in K, in V>.asLoadingCache(
9276 * If the key does not exist, then the suspendable [compute] function is invoked
9377 * to compute a value, unless a specific compute has been provided with the key.
9478 *
95- * If the suspendable computation throws or computes a null value then the
79+ * If the suspendable computation throws or computes a null value, then the
9680 * entry will be automatically removed.
9781 *
9882 * The [reloadCompute] function is invoked to refresh an entry if refreshAfterWrite
9983 * is enabled or refresh is invoked. See full docs [AsyncCacheLoader.asyncReload].
10084 *
101- * The compute functions will execute on the given [scope].
85+ * The given compute functions will execute on the given [scope].
10286 */
10387fun <K : Any , V : Any > Caffeine <in K , in V >.asLoadingCache (
10488 scope : CoroutineScope ,
10589 compute : suspend (K ) -> V ,
10690 reloadCompute : suspend (K , V ) -> V ,
10791): LoadingCache <K , V > {
108- return LoadingCache (scope, true , buildAsync(object : AsyncCacheLoader <K , V > {
92+ return LoadingCache (buildAsync(object : AsyncCacheLoader <K , V > {
10993 override fun asyncLoad (key : K , executor : Executor ): CompletableFuture <out V > {
11094 return scope.async { compute(key) }.asCompletableFuture()
11195 }
@@ -122,7 +106,7 @@ fun <K : Any, V : Any> Caffeine<in K, in V>.asLoadingCache(
122106 * If a requested key does not exist, then the suspendable [compute] function is invoked
123107 * to compute the required values.
124108 *
125- * If the suspendable computation throws or computes a null value then the
109+ * If the suspendable computation throws or computes a null value, then the
126110 * entry will be automatically removed.
127111 */
128112fun <K : Any , V : Any > Caffeine <in K , in V >.asBulkLoadingCache (compute : suspend (Set <K >) -> Map <K , V >): LoadingCache <K , V > {
@@ -145,7 +129,7 @@ fun <K : Any, V : Any> Caffeine<in K, in V>.asBulkLoadingCache(
145129 scope : CoroutineScope ,
146130 compute : suspend (Set <K >) -> Map <K , V >
147131): LoadingCache <K , V > {
148- return LoadingCache (scope, true , buildAsync(AsyncCacheLoader .bulk { keys, _ ->
132+ return LoadingCache (buildAsync(AsyncCacheLoader .bulk { keys, _ ->
149133 scope.async { compute(keys) }.asCompletableFuture()
150134 }))
151135}
0 commit comments