Ionic-storage vs native-storage


#1

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.


#2

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


#3

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


#4

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.


#5

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


#6

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.


#7

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.


#8

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


#9

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


#10

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?


#11

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");
      };
    })
  }

}

#12

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?


#13

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???


#14

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.


#15

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.


#16

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


#17

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.


#18

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.


#19

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.