ionic-team / ionic-storage

Ionic Storage module for Ionic apps
MIT License
434 stars 99 forks source link

Storage cleared everytime the app closes/on refresh #165

Open YogliB opened 5 years ago

YogliB commented 5 years ago

I'm using @ionic/storage v2.2.0 with Ionic v4 and Angular v7, and in development mode, the storage (IndexedDB in that case) is cleared on refreshing the page.

On mobile (with Cordova on Android v7.1.4), the storage is cleared upon closing the app.

I use NO extra settings in my app for the storage and used it just like the instructions here (I installed the npm package and the Cordova plugin).

jcbriones commented 5 years ago

I actually have the same problem! I notice that the cordova-sqlite-storage has an option to set androidLockWorkaround: 1 in the config setting. I tried setting that in the config like this

IonicStorageModule.forRoot({
      androidLockWorkaround: 1,
}),

but it was giving me an error saying StorageConfig does not have androidLockWorkaround

Can anyone please verify. Thank you.

YogliB commented 5 years ago

@jcbriones From the source code (The object inside of the forRoot method):

export interface StorageConfig {
  name?: string;
  version?: number;
  size?: number;
  storeName?: string;
  description?: string;
  driverOrder?: string[];
  dbKey?: string;
}
Taylorsuk commented 5 years ago

Hi @YogliB @jcbriones, I've got the same issue. I don't recall this being the case with the previous v2.1.1.

Have you managed to find a fix?

YogliB commented 5 years ago

@Taylorsuk Nope, just stopped using it...

codewithtushar commented 4 years ago

@YogliB I am facing the same issue what alternative have you used if not using this ?

moconnell9 commented 3 years ago

I am also facing this issue.

YogliB commented 3 years ago

@YogliB I am facing the same issue what alternative have you used if not using this ?

We've moved on to developing PWAs, so now I just use LocalForage.

martiangirlie commented 3 years ago

I'm having this issue as well, anyone find anything new?

Hanzofm commented 3 years ago

Same problem here.

On 'device platforms' (ios/android) works fine but on 'browser' platform the storage is clear every app startup or reload. However without reload or restart works fine.

this is my env:

  IonicStorageModule.forRoot({
            name: 'MyAppDB',
            driverOrder: ['sqlite', 'localstorage', 'indexeddb', 'websql'],
        }),
Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
"@ionic/storage": "2.3.1",
"cordova-browser": "^6.0.0",
"cordova-sqlite-storage": "^5.1.0",

compiled with ionic cordova build browser --prod

And upload www folder to AWS

Some solution or workaround? Someone managed with this?

mlynch commented 3 years ago

Not sure why this would happen, perhaps a browser config issue? About to release v3 in a few weeks so hopefully it addresses this.

argvil19 commented 3 years ago

Still happening on 3.0.4 / Ionic 5.4.16

UPDATE: Found out that this happens when available space is low. Browser gets rid of temporary storage when lacking space. https://developer.chrome.com/docs/apps/offline_storage/#table

aaronbach commented 2 years ago

@argvil19 do you have some kind of workaround? I encounter this problem with @ionic/storage@3.0.6. We are using Ionic Appflow Live Updates. This Bug causes the App to logout on old android devices. If you shutdown the App and reopen it afterwards, you are logged in again, because the storage is loaded correctly.

At the moment I#'m experimenting with saving the data from the storage in a file and reload this file, if the storage is empty.

We are Using the following Drivers:

IonicStorageModule.forRoot({
  driverOrder: [Drivers.IndexedDB, Drivers.LocalStorage]
}),
elreco commented 2 years ago

@aaronbach we have the same problem :( did you find a workaround?

aaronbach commented 2 years ago

@elreco yes and no. We have implemented a step before every Appflow Update, which persists the whole ionic storage to a json file and tries to reloads it everytime you are on the login route.

the workaround caused additional troubles, so we decided to switch off AppFlow Updates on Android. The main reason for this was, that some AppFlow updates ran very long on older Android devices.

elreco commented 2 years ago

@aaronbach thank you so much for your answer! You are right, and appflow updates are very fast on iOS.

Do you think that it can works better if we use a sqlite plugin without the ionic storage package?

Like using this: https://ionicframework.com/docs/native/sqlite and make manual sql queries to save our persistent data?

aaronbach commented 2 years ago

@elreco when you only need storage in a mobile app, it should be worth trying: See https://ionicframework.com/blog/choosing-a-data-storage-solution-ionic-storage-capacitor-storage-sqlite-or-ionic-secure-storage > SqlLite