Add a CacheStore module.
This commit is contained in:
parent
ea1ccbf806
commit
c86532778c
15 changed files with 374 additions and 0 deletions
17
libraries/cachestore/test/build.gradle.kts
Normal file
17
libraries/cachestore/test/build.gradle.kts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
plugins {
|
||||
id("io.element.android-library")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "io.element.android.libraries.cachestore.test"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.libraries.cachestore.api)
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.sessionstorage.test
|
||||
|
||||
import io.element.android.libraries.cachestore.api.CacheData
|
||||
|
||||
fun aCacheData(
|
||||
value: String = "aValue",
|
||||
updatedAt: Long = 0,
|
||||
) = CacheData(
|
||||
value = value,
|
||||
updatedAt = updatedAt,
|
||||
)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.sessionstorage.test
|
||||
|
||||
import io.element.android.libraries.cachestore.api.CacheData
|
||||
import io.element.android.libraries.cachestore.api.CacheStore
|
||||
|
||||
class InMemoryCacheStore(
|
||||
initialData: Map<String, CacheData> = emptyMap(),
|
||||
) : CacheStore {
|
||||
val dataMap = initialData.toMutableMap()
|
||||
|
||||
override suspend fun storeData(key: String, data: CacheData) {
|
||||
dataMap[key] = data
|
||||
}
|
||||
|
||||
override suspend fun getData(key: String): CacheData? {
|
||||
return dataMap[key]
|
||||
}
|
||||
|
||||
override suspend fun deleteData(key: String) {
|
||||
dataMap.remove(key)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue