Comments (2)
Right, further more the serializer can be fully generic and without reflection
class DataCache<T : Any>(
context: Context,
val serializer: KSerializer<T>,
val clazz: Class<T>
) {
val myJSON =
JSON.apply { install(SimpleModule(Timestamp::class.java.kotlin, TimestampSerializer)) }
private val maxSize = 1000
private val diskPath = "FirestoreCoroutines"
private val composedCache: Cache<String, String>
init {
val memoryCache: Cache<String, String> = Cache.createLruCache(maxSize)
val cacheFile = File(context.filesDir, diskPath)
suspend fun get(key: String): T? =
composedCache.get(key).await()?.let {
myJSON.nonstrict.parse(serializer, it)
}
suspend fun getList(key: String): List<T>? =
composedCache.get(key).await()?.let {
myJSON.nonstrict.parse(serializer.list, it)
}
suspend fun set(key: String, value: T) {
try {
composedCache.set(key, myJSON.nonstrict.stringify(serializer, value)).await()
} catch (e: Throwable) {
Timber.e(e)
}
}
suspend fun setList(key: String, value: List<T>) {
try {
composedCache.set(key, myJSON.nonstrict.stringify(serializer.list, value)).await()
} catch (e: Throwable) {
Timber.e(e)
}
}
}
from kotlin-multiplatform-firebase.
@AlexeyKorshun PR is more then welcome
from kotlin-multiplatform-firebase.
Related Issues (15)
- Add https://github.com/Kotlin/kotlinx.serialization
- Setup testing Js
- Move intro to wiki
- iOS implementation
- Code samples
- Add resolutionStrategy
- Native multiplatform DI
- Bind android coroutins to life cycle
- Add https://github.com/russhwolf/multiplatform-settings
- How to use
- Add travis
- Error while compiling sources for iOS
- Exclude Pods from git HOT 1
- JVM support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-multiplatform-firebase.