I'm building an app using AngularJS. I need to store some data across sessions. I thought the $cacheFactory
might be an option. However, I can't figure out where the Cache object actually stores the data.
Can someone tell me how to store data on the client-side across sessions in AngularJS? Is the $cacheFactory
even an option for this scenario?
Thank you
No, it's not an option. The cache is in the JS application memory. As soon as you refresh the page, it's gone.
To cache things across sessions, you can use cookies or the localStorage API. But the better and most reliable place to cache things across sessions is your server-side database.
$cacheFactory
merely stores the data in a JSON dict (calledcaches
at the time of writing) and the data will be lost as soon as the app is reloaded.The only persistent storage option you have while remaining browser compatible is cookies. If you support only modern browsers (>IE8), then you can consider using the HTML5
localStorage
provided by the browser as well.