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