-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
ConcurrentHashMap
for JVM target.
- Loading branch information
1 parent
933de3f
commit d824daa
Showing
6 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.github.reactivecircus.cache4k | ||
|
||
internal expect class ConcurrentMutableMap<Key : Any, Value : Any>() { | ||
val size: Int | ||
val values: Collection<Value> | ||
operator fun get(key: Key): Value? | ||
fun put(key: Key, value: Value): Value? | ||
fun remove(key: Key): Value? | ||
fun clear() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
cache4k/src/jvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.reactivecircus.cache4k | ||
|
||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
internal actual class ConcurrentMutableMap<Key : Any, Value : Any> { | ||
private val map = ConcurrentHashMap<Key, Value>() | ||
|
||
actual val size: Int | ||
get() = map.size | ||
|
||
actual val values: Collection<Value> | ||
get() = map.values | ||
|
||
actual operator fun get(key: Key): Value? { | ||
return map[key] | ||
} | ||
|
||
actual fun put(key: Key, value: Value): Value? { | ||
return map.put(key, value) | ||
} | ||
|
||
actual fun remove(key: Key): Value? { | ||
return map.remove(key) | ||
} | ||
|
||
actual fun clear() { | ||
map.clear() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
cache4k/src/nonJvmMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.reactivecircus.cache4k | ||
|
||
import co.touchlab.stately.collections.IsoMutableMap | ||
|
||
internal actual class ConcurrentMutableMap<Key : Any, Value : Any> { | ||
private val map = IsoMutableMap<Key, Value>() | ||
|
||
actual val size: Int | ||
get() = map.size | ||
|
||
actual val values: Collection<Value> | ||
get() = map.values | ||
|
||
actual operator fun get(key: Key): Value? { | ||
return map[key] | ||
} | ||
|
||
actual fun put(key: Key, value: Value): Value? { | ||
return map.put(key, value) | ||
} | ||
|
||
actual fun remove(key: Key): Value? { | ||
return map.remove(key) | ||
} | ||
|
||
actual fun clear() { | ||
map.clear() | ||
} | ||
} |