Not getting latest data from db on Vercel | Neondb (postgresql)
Answered
Naeemgg posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
this is my route file
while hitting it from
import prisma from "@/prisma/client"
import { NextResponse } from "next/server"
export const GET = async()=>{
try {
data = await prisma.docs.findMany({})
return NextResponse.json(data,{status: 200})}
catch (error) {
console.log(error)
return NextResponse.json({msg:"Something went wrong"},{status:503})}}
while hitting it from
localhost
I'm getting all the latest data but from Vercel
I'm getting old data not the latest oneAnswered by risky
because layout config usually affects the nested page files, but im not sure about route files
33 Replies
![Avatar](https://cdn.discordapp.com/avatars/678259999201427466/1936f7e8963ff0f800f5eb4b43bc833c.webp?size=256)
Clown
Have you tried to actually test cache from
npm run build && npm start
??npm run dev isnt a good indicator of caching
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
yep
![Avatar](https://cdn.discordapp.com/avatars/678259999201427466/1936f7e8963ff0f800f5eb4b43bc833c.webp?size=256)
Clown
or performance
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
I tried with build and start as well
before pushing to vercel
![Avatar](https://cdn.discordapp.com/avatars/678259999201427466/1936f7e8963ff0f800f5eb4b43bc833c.webp?size=256)
Clown
check vercel datacache out and next docs guide on opting out of cache
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
But I'm fetching it like this
const dynamic = await fetch('https://api.vercel.app/products', {
cache: 'no-store',
});
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
prob change revalidate settings or make the route dynamic cache
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
with
no-store
cache?
![Avatar](https://cdn.discordapp.com/avatars/678259999201427466/1936f7e8963ff0f800f5eb4b43bc833c.webp?size=256)
Clown
[opting out of data cache](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#opting-out-of-data-caching)
[Vercel Datacache](https://vercel.com/docs/infrastructure/data-cache)
[Vercel Datacache](https://vercel.com/docs/infrastructure/data-cache)
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
i meant:
export const dynamic = 'force-dynamic'
// or
export const revalidate = 0 // can me greater then 0 if you want it to last longer
i was meaning that nextjs has fetch cache as well as page... you have to make suree both doesn't cache
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
yeah I was thinking of revalidate = 0
let me give revalidate a shot
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
revalidation 0 is not working
🥲
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
can you send your full code of route
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
const [tableData,setTableData] = useState([])
useEffect(()=>{
const getData = async()=>{
const response = await fetch(`/api/get-all-data`,{cache:"no-store"})
const data = await response.json()
console.log("useEffect called")
console.log(data)
setTableData(data)
}
getData()
},[])
this is how I'm hitting from client component
And below is
get-all-data/route.ts
import prisma from "@/prisma/client"
import { NextResponse } from "next/server"
export const GET = async()=>{
try {
data = await prisma.docs.findMany({})
return NextResponse.json(data,{status: 200})}
catch (error) {
console.log(error)
return NextResponse.json({msg:"Something went wrong"},{status:503})}}
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
i don't see your export of revalidation
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
I did it in layout.tsx
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
ahh can you also try manually here
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
in route?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
ye
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
lemme give a min
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
because layout config usually affects the nested page files, but im not sure about route files
Answer
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
building...
Hmmmm
IT WORKED
@risky
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
yay!!!!
![Avatar](https://cdn.discordapp.com/avatars/782907171721314315/13ada0d1b9a03f777d4286e7cbc36194.webp?size=256)
NaeemggOP
![:all_the_things:](https://cdn.discordapp.com/emojis/753872185118162965.png)