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

Add support for expiration or maxAge timestamps #66

Closed
diosney opened this issue Jan 2, 2019 · 13 comments
Closed

Add support for expiration or maxAge timestamps #66

diosney opened this issue Jan 2, 2019 · 13 comments

Comments

@diosney
Copy link

diosney commented Jan 2, 2019

It seems that IndexedDb doesn't have a native and automatic mechanism for data expiration, but could be awesome if in the meanwhile a workaround gets added.

What I mean is something like this, setting a maxAge or something along with the key and in the next get if the value has expired, well, clean it and return null or something automatically by the module.

@cyrilletuzi
Copy link
Owner

As a first note, localStorage and indexedDb are for permanent storage by design.

Could you give a real-world example where you need this feature?

@diosney
Copy link
Author

diosney commented Jan 2, 2019

@cyrilletuzi You are totally right, but this could be useful to invalidate data based on age without having to resort to the session storage, which does not last long after the browser/tab closes.

It is even being considered, it appears, this will be a workaround until the time comes where it will be supported by default, just like cookies does.

One use case for me would be to enforce data expiration on cached results that still needs to be cached but can go stale if left indifinitelly.

I can live without it, since I can enforce this in an higher level, but could be nice if the module take care of this by itself.

See whatwg/storage#11

@cyrilletuzi
Copy link
Owner

Thanks for your feedback.

Understood on a theoretical level: it would be for data needing a longer time in storage than just the session duration, but not permanent.

But I still don't see where this scenario would happen in practice. Do you have a real world example?

@diosney
Copy link
Author

diosney commented Jan 3, 2019

I was thinking to let the user logged in so if it closes the browser and come back, it doesn' t have to do it again, but to force a clean up in the storage after some time has been passed, which in turn will trigger an unauth state in my app.

Maybe this is a little overkill? Haha, sounds very awful when writing it.

@alignsoft
Copy link

alignsoft commented Jan 3, 2019 via email

@diosney
Copy link
Author

diosney commented Jan 3, 2019

@alignsoft @cyrilletuzi Ok, thanks!

@diosney diosney closed this as completed Jan 3, 2019
@cyrilletuzi
Copy link
Owner

@diosney Client-side local storages can be modified by the user. So storing an expiration date for authentification in it could be modified by the user to be valid forever. So yes, as it was said, this scenario should be managed on the server.

But if there are other scenarios, feel free to share.

@diosney
Copy link
Author

diosney commented Jan 3, 2019

@cyrilletuzi Ok, pretty clear, I understood it all, thanks to both of you and happy new year, I missed that :D

@Gbuomprisco
Copy link

I think this would be very useful for short-lived caching. Is it something you'd consider adding?

@cyrilletuzi
Copy link
Owner

@Gbuomprisco what would be the use case?

@Gbuomprisco
Copy link

Gbuomprisco commented Jul 7, 2020

I'd want to use it as a cache for some of my Ajax requests. They'd be short lived, and get back to loading the actual resource after some time.

I know it's not intended as a cache so I am not fussed if you don't intend to add it, and I could easily wrap this to add such functionality, but it'd be pretty handy in cases when you just want to keep a key for a short amount of time before falling back to the source.

@cyrilletuzi
Copy link
Owner

@Gbuomprisco Angular already supports that via @angular/service-worker dataGroups.

I'm using it myself for the same use case you describe.

@Gbuomprisco
Copy link

My case is a bit more specific, as I'm using Cloud Functions (only work as POST) and Firestore

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

4 participants