Next.js Discord

Discord Forum

[Help] All client requests cached server side

Answered
Cook's Petrel posted this in #help-forum
Open in Discord
Cook's PetrelOP
Hey, been trying to wrap my head around this for a couple of hours.
So I have an exported function apiCall which has "use client" at the top of the file and uses js-cookie to insert the custom authentication header into an underlying fetch call. I've made sure to use cache: "no-store" in the fetch options, however it seems that once a call to apiCall has been made, subsequent calls return the first result since running the server (with another user's authentication token). I believe this is related to [Next.js' data caching](https://nextjs.org/docs/app/building-your-application/caching#data-cache) which memoizes results even when cache: 'no-store' is set. The parameters to apiCall in fact do not change, however it accesses the client's cookies to insert as authentication, which breaks on subsequent requests.
Answered by Cook's Petrel
After digging all the way down to my backend... turns out this wasn't a problem with Next.js caching, but my database not dropping a temporary table before releasing the connection back to the pool causing "cached" results. Couple hours of work gone on a simple mistake, but thanks for the replies anyway.
View full answer

4 Replies

@joulev Add `export const revalidate = 0` to the route handler that you call. From Next.js 15 this will no longer be necessary.
Cook's PetrelOP
Route handler? I am just using an async function, not using any of Next's API routes.
Cook's PetrelOP
After digging all the way down to my backend... turns out this wasn't a problem with Next.js caching, but my database not dropping a temporary table before releasing the connection back to the pool causing "cached" results. Couple hours of work gone on a simple mistake, but thanks for the replies anyway.
Answer