-
Notifications
You must be signed in to change notification settings - Fork 8
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to persist the cache in the browser? #15
Comments
@frederikhors Hi there! Thanks for your kind words here 馃槃
We do operate on the same level of abstraction as
Currently鈥攏o. But that's something I long wanted myself, actually. Besides, it's somehow related to SSR (that's inner implementation details), which we'll need to add once Contexts are merged, so why not now? Give me a few days (maybe a week?) to poke at this bear. |
Your answer fills me with shivers of joy! 馃槃 I can help you test even the smallest quibble, and I can help you eventually with any concerns because I've used pretty much every library in existence today to do this. I will be able to test with either Svelte (and SvelteKit) or SolidJS (and SolidStart). Regarding GraphQL: we are planning to remove Therefore we are looking for an "agnostic" store that stores and persists data in the browser asynchronously and fastest!
Offline management is also premature for now. Regarding SSR: I think investing so much time in SSR NOW is premature. I mean that most of our applications are behind login and not publicly accessible because SAAS, CRM and similar WITHOUT SSR. And so far for the few public sites we have we haven't had the need for persistence in SSR (since they then could load from the browser once hydrated). Therefore for us SSR is not a priority. I repeat, I'm here to help. Anything I can do. Long live the bear! And thank you in advance! |
As an update, this takes a lot more time than I anticipated, because after a brief internal discussion we decided that it would be better to implement it in a good way and thorough instead of a poor ad hoc kind of way. FYI, here's a very simple demo of how you can achieve some level of persistence, but it's bad. The problem of persisting changes is essentially the same as SSR and tests: you need to be able to instantiate a store with some pre-defined value and treat it as a fresh piece of data. So I could theoretically come up with an ad hoc solution to this, but instead we decided to implement a nanostores-wide solution. Below is a quote from this message from #17:
So, to summarize, this issue will need to wait for the PR to land in the core (I expect it to happen in August), and then it'll be a breeze to implement persisting in query. (I don't expect you'll be interested in it by then, @frederikhors, but hopefully some other folk will) |
Yeah. I'll patiently wait your amazing work. Thanks! |
@frederikhors Sure! I updated the snippet I shared here before. To persist something, we basically need to do 3 things:
Here's a demo of the result: Screen.Recording.2024-04-16.at.16.13.49.movNotice how it works:
That all is a bit barebones, I understand. My next priority is to introduce some helpers for both offline caching and SSR, so things will be a bit simpler in future. |
Thank you very much, we are considering a switch from tanstack/query to truly offline-first projects perhaps with sqlite in wasm. We need to figure out if it's worth moving from the current tanstack/query to nanostores/query. We will evaluate and if necessary you will hear from me. Great project |
I just found out this amazing project! Congratulations!
In my dreams I would like to replace
@tanstack/query
andurql
entirely withnanostores/query
. It would be a crazy joy! 馃槃The only thing that blocks me now is that I need to persist all the query data (the cache) in the browser (like I do with those libraries).
I was wondering if there is a way to persist the cahce using
IndexedDB
or something else (I prefer not to uselocalStorage
which besides its already well known limitations also has the problem that it is sync and blocks the main thread).@ai suggested me here to use https://developer.mozilla.org/en-US/docs/Web/API/Cache.
I need this to be able to restore data when there is no or intermittent internet (I'm already using PWA).
What do you think?
Once again: thank you for these magical projects!
The text was updated successfully, but these errors were encountered: