Hi Guys , How do you handle caching in shared kmm ...
# multiplatform
d
Hi Guys , How do you handle caching in shared kmm modules ?
p
That’s an extremely broad question. What kind of data do you want to cache and for what reasons? Because this can be as complicated or simple as you want it to be.
d
I want to have caching of a list of objects and display them in case the user is offline
j
There's a range of caching/persistence libraries available for KMM.... https://github.com/cashapp/sqldelight is probably most popular.....depending on data you want to store the following might also be sufficient https://github.com/russhwolf/multiplatform-settings
👍 1
p
Either put them in a database (SQLDelight, Realm, MongoDB, etc), store them in SharedPreferences / UserDefaults (there’s a KMM wrapper around these if you don’t want to write your own) or serialize them to files on disk. So, basically as you would in native code as well
👍 1
d
Thank you guys
2
g
Also I suppose there may be some alternatives depending of your other dependencies and your needs, I'm thinking about network cache, Apollo GraphQL cache, ... (never tested myself)
👍 1
y
I would argue for this last one. Coil has an image cache. Apollo GraphQL has a data aware cache. HTTP libraries will have a smart cache also, that should be able to server stale content if configured correctly. Often simpler than writing your own persistence.
👍 2