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

Is there a way to persist data in browser? #10

Open
frederikhors opened this issue Jul 29, 2021 · 4 comments
Open

Is there a way to persist data in browser? #10

frederikhors opened this issue Jul 29, 2021 · 4 comments

Comments

@frederikhors
Copy link
Contributor

Is there a way to persist data to LocalStorage / IndexedDB to "start from there" for example at PC reboot?

@ConsoleTVs
Copy link
Owner

It is, but just not as part of the default cache nor any implemented one. So you have to implement it yourself (it is really easy!)

You just have to create a class that implements this interface: https://github.com/ConsoleTVs/swrev/blob/master/src/cache.ts#L101

You have the default cache that you can just copy at: https://github.com/ConsoleTVs/swrev/blob/master/src/cache.ts#L146.

Now, instead of relying on Map<string, CacheItem>, you will have to rely on localStorage instead.

Just pass your class to the SWR options: https://github.com/ConsoleTVs/swrev/blob/master/src/options.ts#L17

This is a pretty cool idea tho, I might build that soon.

@frederikhors
Copy link
Contributor Author

Oh wow.

I'm not very good at writing it.

Also because I think it's harder than we think.

urql-graphql/urql#699 here you can find an example when I was using urql in another project.

Thay have persistence but also had many problems. E.g.: how to correctly save in the "idle" phase to not block the main thread? What to choose between localstorage and indexeddb (I mean, the limits of both?). How to handle cache periods? How many time to retain data? Should we delete sensitive data?

I can totally be your scrupulous and accurate beta tester.

Please let me know which branch I can use to test. :)

I'll start using sswr in the next few hours anyway.

@frederikhors
Copy link
Contributor Author

I found this, maybe it can help: https://github.com/Kong/swrv#localstorage

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