houdini icon indicating copy to clipboard operation
houdini copied to clipboard

Alternative storage mechanisms for cache

Open AlecAivazis opened this issue 3 years ago • 15 comments

At the moment, the only storage mechanism supported by the cache holds onto everything in memory. Houdini should provide an out of the box solution for indexdb or local storage so users can decide what's best for their application. The user should also be able to pass a custom solution through the config file.

AlecAivazis avatar Apr 01 '22 23:04 AlecAivazis

This is blocking for us. Example: I open the web app and navigate. I close the app. I re-open it after a few minutes and now there is no internet. I should still see the (old, maybe stale) data. Right now I see nothing but loading spinners!

Urql uses IndexedDB (for the "async" non-blocking behavior), but we can also start with LocalStorage. I think this is really simple to do but I don't know the Houdini code and I don't have time right now to investigate further.

Such a pity, a new project is starting right now and I think we'll stick with urql because of this!

frederikhors avatar Mar 23 '23 12:03 frederikhors

@AlecAivazis @jycouet is there any ETA for this? Just to start, also with LocalStorage only.

Houdini is just too good to go back to using anything else.

frederikhors avatar Mar 23 '23 18:03 frederikhors

In urql, they manage this with 'exchange', in Houdini, it would be with Client Plugin. It's supporting already a lot of use cases. Probably a few directions to explore and see if it's just using it or extending it a bit.

I don't have an ETA in mind, as it's a mix between time, usage, priority, effort, and willingness ^^

jycouet avatar Mar 23 '23 19:03 jycouet

Thanks. May I ask what you use in your apps today? I assume you are using Houdini, but don't you need this? A hot cache that responds immediately and even if the browser is (temporarily) offline?

frederikhors avatar Mar 23 '23 19:03 frederikhors

I'm using it mainly for "Business Tools" where people are on a computer, connected to the internet 24/7. That's why, I don't really have your use case on top of my list today.

But I definitely see the value of it in other scenarios:

  • bad internet connexion / small drops
  • very "static" content that doesn't need too much refresh (SSG some pages?)
  • go away for 2 or 3 days, complete a task on a webapp, come back online and push updates (sync)

Where are you falling to? Or you have something else? 👀

jycouet avatar Mar 23 '23 19:03 jycouet

This is especially useful if you're developing for web app used on phones...

frederikhors avatar Mar 23 '23 19:03 frederikhors

What about something like: https://blog.kowalczyk.info/article/persisted-svelte-store-indexeddb.html and https://github.com/macfja/svelte-persistent-store?

frederikhors avatar Mar 23 '23 20:03 frederikhors

https://github.com/macfja/svelte-persistent-store is amazing! Is the Houdini cache a Svelte Store yet?

frederikhors avatar Mar 23 '23 20:03 frederikhors

This is the urql docs about: https://formidable.com/open-source/urql/docs/graphcache/offline/#custom-storages

frederikhors avatar Mar 23 '23 22:03 frederikhors

@AlecAivazis, you haven't said a word about this, can I ask for your comment?

frederikhors avatar Mar 27 '23 17:03 frederikhors

Hello! It's great to hear from you again 😍

Don't worry, my silence isn't because I don't care about this feature (quite the opposite). I just don't have much to say that jyc hasn't. As I'm sure you can imagine, maintaining Houdini take a LOT of work that has to be balanced against real life and personal needs/motivation. Unfortunately this means we have to split up our attention to ensure everything is attended to and I can't always respond to every thread.

Anyway, I agree this feature is important (its one of the oldest remaining features in the repo) but I just don't have the time to actually champion this through. One hurdle is that the svelte runtime currently has zero dependencies which I'd like to maintain. It shouldn't be too bad to overcome but definitely worth mentioning. If you have the time to dig into this, I would gladly offer any help you need, I dont think it would be that hard to pull off even if it was someone's first exposure to the caching logic

AlecAivazis avatar Mar 27 '23 18:03 AlecAivazis

I would love to be able to do PR like that. But I don't think I can. As soon as I have a second I'll try, maybe I can do it before you.

As I said before, this is a very important thing because it precludes a series of functions that a PWA should provide (I would even say that without it it is better not to use javascript at all and go server-side in some cases using service workers as a caching layer).

Just to understand, the cache resides in memory, but as a simple object or as a Svelte store?

frederikhors avatar Mar 28 '23 11:03 frederikhors

Still nothing, right?

frederikhors avatar Jun 09 '23 10:06 frederikhors

I would love to be able to do PR like that. But I don't think I can. As soon as I have a second I'll try, maybe I can do it before you.

As I said before, this is a very important thing because it precludes a series of functions that a PWA should provide (I would even say that without it it is better not to use javascript at all and go server-side in some cases using service workers as a caching layer).

Just to understand, the cache resides in memory, but as a simple object or as a Svelte store?

I'm just a houdini user like you, but i did dig into the client cache code somewhat. It is a big in-memory object. I actually mostly turn off the cache right now. Better client caching would be good esp for a PWA/hybrid mobile, pluggable would be good, and server-side ssr cache w/redis would be good (more tricky with auth differences).

I would love to work on it, but i'm trying to build a minimum viable product now, maybe look after. On the SSR cache idea, i would like to have something wrapped in sveltekit server endpoints which can use http caching (i don't use apollo)

nohea avatar Jun 09 '23 17:06 nohea