Next.js Discord

Discord Forum

im getting a 304 not modified status in prod, but 200 in localhost

Unanswered
American Robin posted this in #help-forum
Open in Discord
American RobinOP
im calling my api where i get data from my db

20 Replies

American RobinOP
im using vercel for deplo
You need to provide more information if you want to get help
American RobinOP
when i call my api
in localhost everything works fine
i get the latest data
when i call my api in prod i get old data
its smth about the cache i guess
but i dont know how to fix
European sprat
read that to write a post for getting help
American RobinOP
the info above should be enough or?
do i have to disable the cache?
Show some code, maybe there's something going on with how you make the request to the db. Also, what database are you using? Is this an issue with the app router or pages router? And so on, basically provide everything that's relevant to the question
American RobinOP
im using prisma, and a postgres db, the issue is in the app router, it works in localhost, but not in prod, im getting the old data, which is there after deploying first time
American RobinOP
dunno if its a "Fix" i used, a get request to get the data, the first time it worked it gets the newest data, and after this its always this data even if the data refreshs, now i changed it to a post request, where i add an action "getStats" aswell and use case, there it works
Fetch requests get automatically cached, you can control the caching behaviour directly within the fetch function as shown here: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data

But, given that you're using prisma you don't have access to a fetch request since the client doesn't use it but instead uses a Rust based query engine, so the alternative is to use the route segment config options as documented here: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-server-with-third-party-libraries
You could move the prisma query inside a route handler and then make a fetch request to it. That way you can control the caching behaviour as you would with a regular fetch call.
West African Lion
@American Robin Did you find the case for this 304 Not modified bug? I'm hitting it too
Duplicates #304 Not Modified #304 Not Modified, Blank page rendering
West African Lion