Perrier
Perrier

Reputation: 2827

Disable or empty http cache in Angular2

My application has a delete registration function, where I have to send a request to the server to remove my user and of course I have to delete all local data from the device. Request and storage clear done correctly but after registering again with the same user the data from the previous session still showed up on the pages.

This looks like it is caused by the http service cache, and if I call exitApp() after deleting the registration, it is working correctly not displaying data from the previous reg. However, exitApp doesn't seem to work on iOS.

So this is a 2in1 question, sorry.

So How can I tell the http service that every earlier cached requests should now be deleted? Or how can I tell the app on iOS to exit completely?

Upvotes: 1

Views: 998

Answers (1)

chatpitau
chatpitau

Reputation: 1303

You should use the method setRoot to clear DOM cache when you navigate to login screen.

Example :

deleteAccount() {
    this.navCtrl.setRoot(LoginPage);
}

According to Ionic documentation :

By default, pages are cached and left in the DOM if they are navigated away from but still in the navigation stack (the exiting page on a push() for example). They are destroyed when removed from the navigation stack (on pop() or setRoot()).

See here for more details : https://ionicframework.com/docs/v2/api/navigation/NavController/

Upvotes: 1

Related Questions