Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set函数能否增加一个过期时间? #18

Open
DarkiT opened this issue Dec 27, 2018 · 9 comments
Open

set函数能否增加一个过期时间? #18

DarkiT opened this issue Dec 27, 2018 · 9 comments

Comments

@DarkiT
Copy link

DarkiT commented Dec 27, 2018

能否增加一个有效时间功能?

@jaywcjlove
Copy link
Owner

@DarkiT 这个是 localStorage 没有过期时间,文档--> https://developer.mozilla.org/zh-CN/docs/Web/API/Storage/setItem

如果你需要过期时间,使用 cookie 来玩儿,市面上 localStorage 有过期时间的都是向 cookie 里面存储,这里有个cookie的小工具: cookie.js: https://github.com/jaywcjlove/cookie.js

@DarkiT
Copy link
Author

DarkiT commented Dec 27, 2018

可以参考下这个 https://github.com/pamelafox/lscache

@DarkiT
Copy link
Author

DarkiT commented Dec 27, 2018

有个时间选项会方便很多

@jaywcjlove
Copy link
Owner

@DarkiT 这种假过期,好像也是可行的,写的时候写两分数据,其中一条是过期时间,每次查询的时候,取一下,顺便查询一下是否过期。

这种没有意义吧,如果用原生的 get 还是存在的。过期为什么不用 cookie 呢?

@DarkiT
Copy link
Author

DarkiT commented Dec 27, 2018

数据存储量太大了,用cookie流量开销太大

@DarkiT
Copy link
Author

DarkiT commented Dec 27, 2018

他这个在判断过期的时候做了一次判断,如果过期就删除时间和数据,所以过期了原生的get取数也不会有返回

@DarkiT
Copy link
Author

DarkiT commented Dec 27, 2018

@jaywcjlove 抱歉,楼上的回答我理解错你的意思了,原生查询确实会返回数据

@jaywcjlove
Copy link
Owner

@DarkiT 这个想法回头有空我可以实现一下,或者你提交一个PR

@DarkiT
Copy link
Author

DarkiT commented Dec 30, 2018

@jaywcjlove 我也想帮大佬提交PR,可惜是个菜鸟,到现在Git都不怎么会用,只能无耻的当个伸手党。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants