Skip to content

Commit

Permalink
added save parcelable item. fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vardemin committed Jan 31, 2020
1 parent d5ef9c5 commit 4713f2b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions varddb/src/main/java/com/vardemin/varddb/VardStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,25 @@ data class VardStore(val config: VardStoreConfig) {
public suspend fun saveAsync(key: String, value: MutableSet<String>, ttl: Long = -1L, context: CoroutineContext = config.coroutineContext) =
withContext(context) { save(key, value, ttl)}

public fun <T: Parcelable> save(key: String, value: T, ttl: Long = -1L) =
setTTL(key, ttl) {
mmkv.encode(key, value).also { notifyLiveData(key, value) }
}
public suspend fun <T: Parcelable> saveAsync(key: String, value: T, ttl: Long = -1L, context: CoroutineContext = config.coroutineContext) =
withContext(context) { save(key, value, ttl)}

public fun <T: Parcelable> save(key: String, list: List<T>, ttl: Long = -1L) =
setTTL(key, ttl) {
mmkv.encode(key, MarshalUtil.marshall(list)).also { notifyLiveData(key, list) }
}
public suspend fun <T: Parcelable> save(key: String, list: List<T>, ttl: Long = -1L, context: CoroutineContext = config.coroutineContext) =
public suspend fun <T: Parcelable> saveAsync(key: String, list: List<T>, ttl: Long = -1L, context: CoroutineContext = config.coroutineContext) =
withContext(context) { save(key, list, ttl)}

public fun <T: Parcelable> save(key: String, map: Map<String, T>, ttl: Long = -1L) =
setTTL(key, ttl) {
mmkv.encode(key, MarshalUtil.marshall(map)).also { notifyLiveData(key, map) }
}
public suspend fun <T: Parcelable> save(key: String, map: Map<String, T>, ttl: Long = -1L, context: CoroutineContext = config.coroutineContext) =
public suspend fun <T: Parcelable> saveAsync(key: String, map: Map<String, T>, ttl: Long = -1L, context: CoroutineContext = config.coroutineContext) =
withContext(context) { save(key, map, ttl)}

public fun <T> save(key: String, value: T, ttl: Long = -1L) = mmkv.encode(key, value, ttl).also { if (it) notifyLiveData(key, value) }
Expand Down

0 comments on commit 4713f2b

Please sign in to comment.