Where does AngularJS store Cache data

2019-06-26 19:11发布

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

2条回答
冷血范
2楼-- · 2019-06-26 19:31

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.

查看更多
男人必须洒脱
3楼-- · 2019-06-26 19:49

$cacheFactory merely stores the data in a JSON dict (called caches 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.

查看更多
登录 后发表回答