-
Notifications
You must be signed in to change notification settings - Fork 36
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
Making sense of different layers of caching #132
Comments
Heyo, super confusing topic :)
Apollo Client adds
Tbh., in my eyes only I have to admit that I don't particularly like the Next Data Cache since it caches APIs under the assumption that no other non-Next.js API consumer will ever cause any data writes there. (Even a Next.js instance hosted on a different host in manual hosting, but interacting with the same DB/API could break this assumption.)
Once necessary APIs land in the React core (hopefully in React 19), we'd love to take the learnings from here and create a framework-agnostic solution as part of |
Amazing, thank you for the detailed response! This is exactly the info I needed. 🙏 We do indeed manually host, so will be careful here. Definitely like the idea of a framework-agnostic solution, hopefully that ends up being feasible! Feel free to close or leave this open if it's helpful for others. |
How would you do things like in my situation I'm dealing with a schema where different types represent the same underlying object (swagger wrapper) so i have to manually update the cache after mutating. |
@dpnova in the browser, you could just continue doing that. |
Hi there! Thanks for all your work on this (especially the RFC, blog posts, and discussions between you and Dan--immensely helpful to me). I've been doing a deep dive across this repo, the Next.js caching page, and various stack overflow posts trying to piece it all together.
I've been testing using this in my org's new frontend, and while I believe I've got it working, I'm still struggling to understand the different layers of caching, how these new Apollo Client instances fit into that, and ultimately how to structure queries.
The different layers
Going to do my best to explain based on my current understanding, feel free to correct.
In a standard Next.js 14 app, there are four caching layers (per their docs):
GET
fetch requests during the RSC render pass. Only caches for the lifetime of a server request during rendering. Can opt out withAbortController
.no-store
orunstable_noStore
.revalidate = 0
ordynamic = force-dynamic
or if opted out of Next Data Cache already).Adding ApolloClient into the mix we now have:
React.cache
to share the instance for a single request. Seems to work withnext/cookies
in my limited testing. This works with the Next.jsData Cache
as well.Data Cache
as well.Questions
cache-first
,cache-and-network
, etc in this new world? Seems like there's overlap with the Next data cache. Do I need them at all?@apollo/client/link/http
'screateHttpLink
to build ourHTTPLink
instead of a newHTTPLink
. We then usefrom
to chain this with some other links for debugging, auth, etc like we'd do in any Apollo project. Is there any difference or best practice here?@apollo/client
or do you all plan to keep it separate? Just curious. Having it separate right now actually helps us maintain some separation between old and new in our monorepo.Again, thank you so much. Please let me know if there's a better format or place for these questions. I was going to post in Discord, but felt like it might be more readable/helpful to others here. I'm also generally curious around best practices for data fetching going forward like in this issue, since Next seems to recommend component-level fetching and relying on deduping, but this post is already so long I'll leave that out for now.
The text was updated successfully, but these errors were encountered: