Skip to content
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

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from
Open

Improve Unstable Cache Docs #65942

wants to merge 2 commits into from

Conversation

Arinji2
Copy link
Contributor

@Arinji2 Arinji2 commented May 19, 2024

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.

@Arinji2 Arinji2 requested review from a team as code owners May 19, 2024 04:52
@Arinji2 Arinji2 requested review from timeyoutakeit and leerob and removed request for a team May 19, 2024 04:52
@ijjk ijjk added the Documentation Related to Next.js' official documentation. label May 19, 2024
@chrisb2244
Copy link

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).

@Arinji2
Copy link
Contributor Author

Arinji2 commented May 19, 2024

Yup, we get a lot of questions regarding keyparts in the nexts discord ourselves :D
Nice to know you as a user also like the changes :)



export default async function Page({ params }: { params: { userID: string } }) {
const getCachedUser = unstable_cache(
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link

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.
@Arinji2 Arinji2 requested a review from leerob May 22, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Related to Next.js' official documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants