-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
32 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...help-and-troubleshooting/100-help-articles/430-nextjs-prisma-client-dynamic.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: 'Best practices for using Prisma Client with Next.js and Next.js Data Cache' | ||
metaTitle: 'Best practices for using Prisma Client with Next.js and Next.js Data Cache' | ||
metaDescription: 'Learn best practices to avoid issues with route caching in Next.js' | ||
--- | ||
|
||
## Problem | ||
|
||
When deploying a Next.js app, you may run into an issue where your queries are not updating or displaying the correct content. Or, you may find that it takes a long time for newly created objects to show up in your queries. | ||
|
||
In these cases, you are most likely seeing data persisted in the [Next.js Data Cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache). Any `fetch` request has its result cached by default, leading to possibly unwanted results as Prisma uses `fetch` internally. | ||
|
||
## Solution | ||
|
||
To opt-out of the Next.js Data Cache, you can [disable caching for a specific route](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic) using the `"force-dynamic"` config option so that up to date data is always returned and no caching happens. | ||
|
||
You can add `"force-dynamic"` like this: | ||
|
||
```ts | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import prisma from './db' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export async function GET(request: NextRequest, response: NextResponse) { | ||
// your code would go here | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters