supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

Caching support? #396

Open madeleineostoja opened 2 years ago

madeleineostoja commented 2 years ago

Feature request

Is your feature request related to a problem? Please describe.

Currently the Supabase JS client feels like a simple wrapper around fetch and postgrest. Notably it doesn't provide anything in the way of caching of data to reduce requests to the server on repeated queries, and patchy network support. This is in contrast to Firebase which provides all of this out of the box.

Describe the solution you'd like

Bake caching into supabase-js so it's performant and robust by default, ideally with optimistic mutation support as well

Describe alternatives you've considered

BYO querying layer that supports caching and eager mutations, like react-query. Adds an extra layer of abstraction and complexity onto the client.

Additional context

N/A

vhscom commented 2 years ago

SWR libraries should be kept separate so this library stays small and focused. GraphQL does caching. Have you looked at enabling the GraphQL extension on a database created after Mar 28 to see the impact on performance? Among other things, another option is to add Redis to your app. And if you wanted to see Redis within Supabase you can log your vote here.

madeleineostoja commented 2 years ago

The supabase team has already said they're working on offline and optimistic update support, so I think this falls well within the purview of the JS SDK if that's the case. If that is no longer the case then getting clarity about exactly what the goals of this SDK is would allow dev teams like ours to better plan our tech stack until supabase hits stable.

soedirgo commented 1 year ago

I suppose this falls under https://github.com/supabase/supabase/discussions/357 - the client lib is the right place for it.

pingiun commented 1 year ago

For my application I want to do getUser on lots of different pages, which does a new request every time. It would be nice if the User object from localstorage is retrieved instead if it is fresh enough (a couple minutes maybe)

EDIT: Nvm I just found out you can use getSession for this, because the user is stored in the session

sampl commented 1 year ago

It seems like the idea of the js library (combined with RLS etc) is not having to build a backend, so IMO Redis seems like kind of overkill.

Caching makes a ton of sense, not just to save db/network but for speed. It's sort of one of those features that you don't think about until you realize you don't have it.

Is there any obvious way to pair another library with supabase-js to get this effect? Maybe using the rest endpoint with react query? Just spitballin. (I haven't tried the GraphQL extension to test perf fwiw)

rotimi-best commented 1 month ago

Any way forward to this in 2024?