Ionic-storage vs native-storage

I am looking for a persistent key-value storage. LocalStorage would be fine, but sadly it can get deleted by the OS if the device is low on memory. It seems that there are 2 “plugins” created to solve that problem. Ionic-storage (+sqlite) https://github.com/driftyco/ionic-storage or the native-storage plugin https://ionicframework.com/docs/v2/native/nativestorage/. However, I could not really find any big differences between the two besides the technical implementation and some api differences.

Are there any aspects that I might have overlooked? Which way would you guys recommend for a small app that only uses it as a key-value storage?

Thanks for your help.

5 Likes

What did you end up going with? I’m in the same predicament.

3 Likes

add me to the list of which one to use as well…
i have 3 key/pair values i need to store, one is a guid, the other 2 are numbers

I went with NativeStorage. It was the most lightweight solution for storing a few key/value pairs in a persistent manner. Ionic Storage (and sqlite) are awesome, but more overhead than I need atm.

ur not worried about the OS clearing memory on low storage? thats kinda got me worried.

but ya i agree for simple key/pair the rest might be overkill

iOS will certainly clear LocalStorage on low memory, but the NativeStorage plugin doesn’t utilize LocalStorage which means you don’t have to worry about that with it.

2 Likes

Major drawback to NativeStorage…It only works on a real device. You will need another solution for the browser. Ionic Storage is great because it selects the optimal engine under the hood. So maybe I’ll just stick with that lol.

1 Like

I would highly recommend going with IonicStorage if its a small set of key value pairs to be stored.

I have installed @ionic/storage and cordova sqlite. Also Iam import storage in module and providers. But iam getting get of undefined error

Since you can’t use native storage when running in browser, what is the recommended solution if I need to run it in browser while development and make it work on devices once publish to app store?

I created this little provider, where I check the platform, I use it as a flag,
if it returns browser than it dev environment. I mainly use the in my http.get urls
to let me know if i need to use proxy url or live url.

more code but, it works

import { Injectable } from '@angular/core';
import {Platform} from "ionic-angular";


@Injectable()
export class PlatformProvider {

  constructor(private platform: Platform) {
    console.log('Hello PlatformProvider Provider');
  }

  checkPlatform() {
    return new Promise(resolve => {
      if (this.platform.is('mobileweb') || this.platform.is('core')) {
        resolve("browser");
      } else {
        resolve("mobile");
      };
    })
  }

}
1 Like

Omg, wrapping a sync api property in a provider and in a new Promise to make it seemibgly async.

Isn’t this a waste of coding time?

Hello i Have a question
Why when i am restarting my app
all the data stored in storage are lost??
in which storage do we have a “forever” save???

1 Like

You mean you go to system setting and clear cache (reset app).
If you did it, it mean all localStorage will be cleared, so data will empty.

1 Like

Well, seeing the way the three dual at one—another it would be a great idea to choose the one you favor being LocalStorage, Ionic Storage or Native Storage you’d need to design an algorithm regardless to pick the appropriate storage.

So, @Ben1nB1ack has the correct idea by designing an algorithm for that cause it seems very useful.

Just make sure you correctly apply the selected Storage in the correct manner. I however was surprised to find out that the LocalStorage gets cleared upon low memory.

Ionic usually (or from what I can remember); designs their in—app plugins and then around v2 they designed Natives which are designed with Cordova’s Native Plugin objective in mind of operating within the device system itself and not the in—app operations.

Hope this cleared some up for some of you. If I’m wrong, feel free to correct me; but that’s how memory serves.

1 Like

No i mean when i refresh my chrome page with the app running
all the stored data get lost

Hm… If you’re running it in your browser, inspect the Storage Spaces. If you’re using your phone app, deploy it from your CLI using debug methods so you can watch what happens on your CLI.

I want to know about this as well.

Ionic storage vs Native storage…
which one can store the data longer?
I don’t want my OS to suddenly remove all data.

What exactly further do you need to know?
Longer? Can you explain?
If you have the Ionic Plugins it shouldn’t automatically remove your storage data.
However, if you use Local Storage (the default); it’ll be cleared whenever the phone attempts to free up storage space to allow the user to keep using their phone.

1 Like