Hello everyone,
Does anyone know what is the difference between Storage and LocalStorage of Ionic2 ? I am not very clear when reading it. Please kindly explain me.
Thanks in advance.
Hello everyone,
Does anyone know what is the difference between Storage and LocalStorage of Ionic2 ? I am not very clear when reading it. Please kindly explain me.
Thanks in advance.
There is a nice short description at the Ionic documentation
Basically localStorage is a browser owned key/value system. You can store up to 5Mb depending on the platform. However the OS you are running your app under can decide to delete its content if your app is on the background and OS needs memory.
The Storage plugin will try to use permanent storage such SQLite. Therefore your data lives as long as your app is installed.
So details that need to be persisted such as first launch flag or authentication token and so on, need to go under Storage, where you can decide to store some recurrent data you get from the server at localStorage..
https://stackoverflow.com/a/19869560/6642869 you may refer to this , and this might clear your doubt. In a nutshell...
LOCAL STORAGE
For example you have an app, and as you launch it, you make an sql query and retrieve all its data on your phone and then you use that data within your application and it will be displayed to the user via local storage. This will help user to see data when you are without internet until the time the user does something that will clear the data from your phone (suppose if you logout, your local DB will be cleared). Until the user logs out or clear app data, he can see the data even without internet but will not be able to make any updations
STORAGE:
For example you launch your application, and then as you fetch the data it is stored by you in a global array (in terms of ionic 2), then you display that data on your page from your local array. The difference here is, as you are fetching details from the server your global array is getting filled and then you can make activities in your application for example you like a post, the like will be reflected at the same instant and server end communication will take place from background with no worry of reloading the app again and again. But once you exit from your app the global array will be cleared. So no data will be visible without internet.
Briefly we can say like storage in ionic 2 works dynamically and make our data fetching and posting quick where as for local storage it helps you look at the content even in offline mode.
Apart from what's mentioned above:
localStorage is synchronous and the ionic Storage is asynchronous.
In my case using localStorage was more convenient because I had to synchronously receive stored data.