Opting out of caching clarification
Answered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
In the following documentation about opting out of caching https://nextjs.org/docs/app/building-your-application/routing/route-handlers#opting-out-of-caching it says,
And in the example code:
At which point in the sample code determines that I'm opting out of caching?
UsingRequestobject with theGETmethod.
And in the example code:
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const id = searchParams.get('id')
const res = await fetch(`https://data.mongodb-api.com/product/${id}`, {
headers: {
'Content-Type': 'application/json',
'API-Key': process.env.DATA_API_KEY!,
},
})
const product = await res.json()
return Response.json({ product })
}At which point in the sample code determines that I'm opting out of caching?
Answered by B33fb0n3
The opt out is right on top:
In this case, because he use the
const { searchParams } = new URL(request.url)In this case, because he use the
request object (in this case to get the searchParams)5 Replies
@Saltwater Crocodile In the following documentation about opting out of caching https://nextjs.org/docs/app/building-your-application/routing/route-handlers#opting-out-of-caching it says,
> Using `Request` object with the `GET` method.
And in the example code:
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const id = searchParams.get('id')
const res = await fetch(`https://data.mongodb-api.com/product/${id}`, {
headers: {
'Content-Type': 'application/json',
'API-Key': process.env.DATA_API_KEY!,
},
})
const product = await res.json()
return Response.json({ product })
}
At which point in the sample code determines that I'm opting out of caching?
The opt out is right on top:
In this case, because he use the
const { searchParams } = new URL(request.url)In this case, because he use the
request object (in this case to get the searchParams)Answer
Saltwater CrocodileOP
@B33fb0n3 Thanks for the reply. I assume that Next is doing something special to know when the request obj is used then.
yep it does analyse the source code during the compile step and determine that automatically
@joulev yep it does analyse the source code during the compile step and determine that automatically
Saltwater CrocodileOP
thanks for the help!
happy to help