diff --git a/build-logic/gradle.properties b/build-logic/gradle.properties index 771574b..917f4a3 100644 --- a/build-logic/gradle.properties +++ b/build-logic/gradle.properties @@ -5,4 +5,3 @@ org.gradle.configuration-cache=true org.gradle.configuration-cache.problems=warn kotlin.code.style=official -kotlin.experimental.tryK2=true diff --git a/build-logic/src/main/kotlin/io/github/reactivecircus/cache4k/buildlogic/convention/ConventionPlugin.kt b/build-logic/src/main/kotlin/io/github/reactivecircus/cache4k/buildlogic/convention/ConventionPlugin.kt index b19ffcc..6f8f65d 100644 --- a/build-logic/src/main/kotlin/io/github/reactivecircus/cache4k/buildlogic/convention/ConventionPlugin.kt +++ b/build-logic/src/main/kotlin/io/github/reactivecircus/cache4k/buildlogic/convention/ConventionPlugin.kt @@ -182,23 +182,20 @@ private fun KotlinMultiplatformExtension.configureTargets(project: Project) { mingwX64() applyDefaultHierarchyTemplate() + @Suppress("UnusedPrivateProperty") sourceSets { - val jvmAndIos by creating { + val nonJvmMain by creating { dependsOn(commonMain.get()) } - iosMain.get().dependsOn(jvmAndIos) - jvmMain.get().dependsOn(jvmAndIos) - - val nonJvm by creating { - dependsOn(commonMain.get()) + val jvmLincheck by getting { + dependsOn(jvmMain.get()) } - jsMain.get().dependsOn(nonJvm) - @Suppress("UnusedPrivateProperty") + jsMain.get().dependsOn(nonJvmMain) val wasmJsMain by getting { - dependsOn(nonJvm) + dependsOn(nonJvmMain) } - appleMain.get().dependsOn(nonJvm) - linuxMain.get().dependsOn(nonJvm) - mingwMain.get().dependsOn(nonJvm) + appleMain.get().dependsOn(nonJvmMain) + linuxMain.get().dependsOn(nonJvmMain) + mingwMain.get().dependsOn(nonJvmMain) } } diff --git a/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt b/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt new file mode 100644 index 0000000..bd98ee0 --- /dev/null +++ b/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt @@ -0,0 +1,10 @@ +package io.github.reactivecircus.cache4k + +internal expect class ConcurrentMutableMap() { + val size: Int + val values: Collection + operator fun get(key: Key): Value? + fun put(key: Key, value: Value): Value? + fun remove(key: Key): Value? + fun clear() +} diff --git a/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/KeyedSynchronizer.kt b/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/KeyedSynchronizer.kt index 3f7e1bc..d9f006f 100644 --- a/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/KeyedSynchronizer.kt +++ b/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/KeyedSynchronizer.kt @@ -1,6 +1,5 @@ package io.github.reactivecircus.cache4k -import co.touchlab.stately.collections.IsoMutableMap import kotlinx.atomicfu.locks.reentrantLock import kotlinx.atomicfu.locks.withLock import kotlinx.coroutines.sync.Mutex @@ -11,7 +10,7 @@ import kotlinx.coroutines.sync.withLock */ internal class KeyedSynchronizer { - private val keyBasedMutexes = IsoMutableMap() + private val keyBasedMutexes = ConcurrentMutableMap() private val mapLock = reentrantLock() @@ -40,7 +39,7 @@ internal class KeyedSynchronizer { mutexEntry.counter++ // save the lock entry to the map if it has just been created if (keyBasedMutexes[key] == null) { - keyBasedMutexes[key] = mutexEntry + keyBasedMutexes.put(key, mutexEntry) } return mutexEntry.mutex diff --git a/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/RealCache.kt b/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/RealCache.kt index 08e6b5b..48e2541 100644 --- a/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/RealCache.kt +++ b/cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/RealCache.kt @@ -1,6 +1,5 @@ package io.github.reactivecircus.cache4k -import co.touchlab.stately.collections.IsoMutableMap import co.touchlab.stately.collections.IsoMutableSet import kotlinx.atomicfu.AtomicRef import kotlinx.atomicfu.atomic @@ -38,7 +37,7 @@ internal class RealCache( private val eventListener: CacheEventListener?, ) : Cache { - private val cacheEntries = IsoMutableMap>() + private val cacheEntries = ConcurrentMutableMap>() /** * Whether to perform size based evictions. @@ -138,7 +137,7 @@ internal class RealCache( writeTimeMark = atomic(nowTimeMark), ) recordWrite(newEntry) - cacheEntries[key] = newEntry + cacheEntries.put(key, newEntry) } onEvent( oldValue?.let { diff --git a/cache4k/src/jvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt b/cache4k/src/jvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt new file mode 100644 index 0000000..f63f129 --- /dev/null +++ b/cache4k/src/jvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt @@ -0,0 +1,19 @@ +package io.github.reactivecircus.cache4k + +import java.util.concurrent.ConcurrentHashMap + +internal actual class ConcurrentMutableMap { + private val map = ConcurrentHashMap() + + actual val size: Int get() = map.size + + actual val values: Collection get() = map.values + + actual operator fun get(key: Key): Value? = map[key] + + actual fun put(key: Key, value: Value): Value? = map.put(key, value) + + actual fun remove(key: Key): Value? = map.remove(key) + + actual fun clear() = map.clear() +} diff --git a/cache4k/src/nonJvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt b/cache4k/src/nonJvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt new file mode 100644 index 0000000..ff14e29 --- /dev/null +++ b/cache4k/src/nonJvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt @@ -0,0 +1,19 @@ +package io.github.reactivecircus.cache4k + +import co.touchlab.stately.collections.IsoMutableMap + +internal actual class ConcurrentMutableMap { + private val map = IsoMutableMap() + + actual val size: Int get() = map.size + + actual val values: Collection get() = map.values + + actual operator fun get(key: Key): Value? = map[key] + + actual fun put(key: Key, value: Value): Value? = map.put(key, value) + + actual fun remove(key: Key): Value? = map.remove(key) + + actual fun clear() = map.clear() +} diff --git a/gradle.properties b/gradle.properties index 6b111db..9600e9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,3 @@ org.gradle.configureondemand=true org.gradle.caching=true kotlin.code.style=official -kotlin.experimental.tryK2=false