Skip to content

Commit 0b3be33

Browse files
committed
fix: use ConcurrentHashMap for thread-safety
1 parent 8dc99c7 commit 0b3be33

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

app/src/main/java/to/bitkit/data/backup/VssStoreIdProvider.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import to.bitkit.data.keychain.Keychain
55
import to.bitkit.env.Env
66
import to.bitkit.utils.Logger
77
import to.bitkit.utils.ServiceError
8+
import java.util.concurrent.ConcurrentHashMap
89
import javax.inject.Inject
910
import javax.inject.Singleton
1011

1112
@Singleton
1213
class VssStoreIdProvider @Inject constructor(
1314
private val keychain: Keychain,
1415
) {
15-
private val cachedStoreIds: MutableMap<Int, String> = mutableMapOf()
16+
private val cachedStoreIds: MutableMap<Int, String> = ConcurrentHashMap()
1617

1718
fun getVssStoreId(walletIndex: Int = 0): String {
1819
synchronized(this) {
@@ -34,15 +35,11 @@ class VssStoreIdProvider @Inject constructor(
3435
}
3536

3637
fun clearCache() {
37-
synchronized(this) {
38-
cachedStoreIds.clear()
39-
}
38+
cachedStoreIds.clear()
4039
}
4140

4241
fun clearCache(walletIndex: Int) {
43-
synchronized(this) {
44-
cachedStoreIds.remove(walletIndex)
45-
}
42+
cachedStoreIds.remove(walletIndex)
4643
}
4744

4845
companion object {

0 commit comments

Comments
 (0)