Search code examples
c#xamarinxamarin.formsnsuserdefaultsakavache

Xamarin - Akavache vs Native Key-value Store such as NSUserDefaults


Both seem to be ways to store key value pairs. I am trying to decide what to use with my xamarin forms app. I would like the information saved to be available on connected devices. I see akavache states that iOS and UWP backs up to the cloud.

What I'm trying to do: -Save 3 settings such as play a sound when scanned, or auto login. -Save login information and login token for Web calls.

I can store all of that in NSUserDefaults (iOS) and be fine. Akavache claims that the items in the Secure blob are encrypted and synced. That sounds better for login information.

Akavache doesn't seem to support mobile 100% due to not having a place to put the shutdown method for a mobile app lifecycle.

So with the preliminaries out of the way, which is better for performing the tasks I need, the native settings store for each platform or akavache?

Maybe it is best to use both? Akavache for the login info and native settings for the settings?


Solution

  • The encryption story with Akavache is a little misleading :-/ It provides the ability for you the user to implement but not an actual implementation for encryption.

    I have a sample here I did https://github.com/PureWeen/Akavache.Samples

    Where you can see an encryption implementation

    I don't feel like the life cycle part is that bad... I just Flush() Akavache during Activity Destroy and haven't had issues with it. The main thing with "flushing" is that you're just trying to persist anything that's inflight before the app is unloaded from memory. You're really just talking about a couple milliseconds to make sure anything inflight gets persisted. If you tell something to save then literally the same moment the user closes the app. I would call it fairly edge condition.

    Personally I just use Xamarin.Auth to store all my "credential" based things (Bearer Tokens, Username, pwds) that way it just uses native things for encrypting.