Weird caching/stale results problem, Nextjs
For context, I am using Neon with Drizzle ORM in a deployed NextJS 14 app (appdir).
I've written multiple simple queries that look like this:
These queries are either used in a single server component that is periodically revalidated, or in "route.ts" files which is the nextjs naming convention for custom request handlers, and in that case it acts as an API endpoint, so that data can be fetched dynamically.
The problem I have is with a different, more complex query I wrote:
This query is only used in a route.ts file (query endpoint). The problem with it is that it almost always returns stale data in both production and development. I can mark a lesson as completed as some user, but it keeps returning stale data, and I can't figure out why.
After some time, I found a possible solution, that doesn't make much sense to me.
I've written multiple simple queries that look like this:
These queries are either used in a single server component that is periodically revalidated, or in "route.ts" files which is the nextjs naming convention for custom request handlers, and in that case it acts as an API endpoint, so that data can be fetched dynamically.
The problem I have is with a different, more complex query I wrote:
This query is only used in a route.ts file (query endpoint). The problem with it is that it almost always returns stale data in both production and development. I can mark a lesson as completed as some user, but it keeps returning stale data, and I can't figure out why.
After some time, I found a possible solution, that doesn't make much sense to me.
