-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Improve Unstable Cache Docs #65942
base: canary
Are you sure you want to change the base?
Improve Unstable Cache Docs #65942
Conversation
Just a user, but a change to the docs like this (particularly the example added) looks like it illustrates the difference and a potential use case quite clearly. I also agree that the current docs could use this kind of addition (how to best choose keyParts vs tags was not previously clear to me). |
Yup, we get a lot of questions regarding keyparts in the nexts discord ourselves :D |
|
||
|
||
export default async function Page({ params }: { params: { userID: string } }) { | ||
const getCachedUser = unstable_cache( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove everything but the function call and import from this code snippet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well my thought process was that the example should ideally be like a real world thing, so the params from the page..
Just to confirm you want me to remove all the page specific code right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leerob this example showcases that if you used variables that is not passed as the parameter of the unstable_cache function, it needs to be added to the keyParts.
We can make this example simpler but we would still need to communicate the gotchas to the users if a closure is used inside the function wthout passing it as arguments (perhaps in a separate section)
Removed the extra keyParts vs tags differences, and instead modified the description for both.
Unstable Cache has always had a very lacking documentation page, even though it adding its own new feature
key parts
. Its a normal occurrence for us in the NextJS Discord to see new people and more advanced users question what is the use of key parts, since the example in the docs. was very lacking.I have made a few changes, like adding a much more functional example which showcases all the features of unstable cache, and also a small difference section between tags and key parts.