问题描述
我在存储大量客户端数据时遇到问题,我无法决定哪种方式更好.现在我正在使用 AngularJS 的 cacheFactory,它工作正常,但所有数据都使用新会话重新加载.是否值得改用本地存储?
I have a problem of storing a lot of client-side data, and I can't decide which way is better. Now I'm using AngularJS's cacheFactory, it works fine, but all data reloads with a new session. Is it worth to use local storage instead?
推荐答案
如果您的目标是存储客户端和持久数据,则不能使用 $cacheFactory,它只是缓存当前会话的数据.
If your goal is to store client-side and persistent data, you can't use the $cacheFactory, which just caches the data for the current session.
一种解决方案是使用新的本地存储 API.这个很棒的 Angular 模块 为您完成所有肮脏的工作,甚至回退到旧浏览器的 cookie!
One solution is to use the new local storage API. This awesome Angular module makes all the dirty job for you, and even falls back to cookies for old browsers!
这篇关于本地存储 vs AngularJS $cacheFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!