Skip to content Skip to sidebar Skip to footer

Best Practices For Clearing Data In Services On Logout In Angularjs

I have several services which uses a webservice and caches a lot of the results.By caching i mean storing in a variable on the service. When a user logs out the data should be clea

Solution 1:

You can create a service which is responsible clearing all the the data from the other services. In this case you only have to call the "clear" method of this service, and implement the individual clear calls inside of this one (so only implemented once).

This gives you also the advantage that you have an overview of which services data need to be cleared all the time, since you might have exceptions in the future.

Also see this answer for your reference: Injecting a service into another service in angularJS

Solution 2:

you can use a full page refresh:

$window.location.reload();

this will restart the whole state of your application

another solution could be to store everything in session storage and then clear it on log out:

sessionStorage.clear();

Post a Comment for "Best Practices For Clearing Data In Services On Logout In Angularjs"