Angularjs:为$ cacheFactory到期日期 [英] Angularjs: date expiration for $cacheFactory

查看:108
本文介绍了Angularjs:为$ cacheFactory到期日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的$ cacheFactory应用程序添加缓存,但是当用户关闭浏览器,然后重新打开,左右浏览产品缓存中的数据已过期。

I have added cache in my application with $cacheFactory, but when the user close the browser and then reopen, the cache data about the browsed products is expired.

有没有什么办法让它长?把过期或某事的日期这样?

Are there any way to make it longer? put a date of expiration or something like that?

感谢。

编辑:我想也许不得不使用 Breeze.js ,但在此之前这个我想知道如果你们知道这是可能的angularjs做到这一点(我读的API和有它没有资料:S)。

I would maybe have to use Breeze.js, but before this I wanted to know if any of you know if it is possible to do it with angularjs (I read the API and there is no info about it :S).

编辑2:的帮助,我在其中使用$ cacheFactory的方式是这样的的jsfiddle code

Edit 2: to help, the way in which I use $cacheFactory is like this JSFiddle code.

factory('SomeCache', function($cacheFactory) {
    return $cacheFactory('someCache', {
        capacity: 3 // optional - turns the cache into LRU cache
    });
}).

修改3: Lawnchair是不是一种选择,它存储在一个javascript数组,并关闭浏览器后不持续的数据。

Edit 3: Lawnchair is not an option, it stores in a javascript array and doesn't persists the data after closing the browser..

推荐答案

$ cacheFactory在内存中存储的浏览器,这意味着它不会在连刷新页面仍然存在,更不用说关闭并重新打开浏览器。

$cacheFactory uses in-memory browser storage, which means it doesn't persist across even a page refresh, let alone closing and re-opening the browser.

如果你想跨越缓存加载页面和浏览器会话的数据,你要找的localStorage。在这里看到一个很简单的例子:

If you want to cache data across page loads and browser sessions, you're looking for localStorage. See here for a very simple example:

http://jsbin.com/acokis/2/edit

我想你会想看看 amplify.js 或的 lawnchair.js ,因为他们管理的localStorage提供很好的包装,还也为不支持localStorage的浏览器提供备用适配器(后备选项荣获 ŧ坚持跨页,虽然刷新)。

I think you'll want to look at amplify.js or lawnchair.js as they provide nice wrappers for managing localStorage, also also provide fallback adapters for browsers that don't support localStorage (fallback options won't persist across page refreshes though).

这篇关于Angularjs:为$ cacheFactory到期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆